public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String str = in.nextLine();
String newStr = str.replace('{', '(');
newStr = newStr.replace('[', '(');
newStr = newStr.replace('}', ')');
newStr = newStr.replace(']', ')');
Stack<Character> stack = new Stack<>();
int max = 0;
int cur = 0;
for(char c:newStr.toCharArray()){
if(c == '('){
stack.push(c);
cur++;
max = Math.max(max, cur);
} else {
stack.pop();
cur--;
}
}
System.out.println(max);
}
}
}