import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
String str = reader.readLine();
System.out.println(getKuo(str));
}
static int getKuo(String str){
int n = str.length();
char[] chars = str.toCharArray();
int[] dp = new int[n];
dp[0] = 0;
int cnt = 0;
for(int i=1;i<n;i++){
if(chars[i] == '('){
dp[i] = 0;
}
if(chars[i] == ')'){
int pre = i - dp[i-1] - 1;
if(pre >= 0 && chars[pre] == '('){
if(pre > 0) {
dp[i] = dp[i - 1] + 2 + dp[pre - 1];
}else {
dp[i] = dp[i - 1] + 2;
}
}
}
cnt = Math.max(cnt, dp[i]);
}
return cnt;
}
}
/*
(()())
) 这个之前的有效是 ()(), 找到此之前的那个字符
如果是 ( ,那么匹配上了
*/