#include<iostream>
#include<map>
#include<stack>
using namespace std;
int solveMethod(string str)
{
if(str.size() % 2 == 1)
{
return 0;
}
stack<char> stack;
map<char, char> pairs{{')', '('},{'}', '{'},{']', '['}};
int maxDepth = 0;
for(char ch : str)
{
if(pairs.count(ch))
{
// 遇到了需要出栈的符号
if(stack.empty() || stack.top() != pairs[ch])
{
return 0;
}
maxDepth = std::max(maxDepth, (int)stack.size());
stack.pop();
}
else
{
stack.push(ch);
}
}
return maxDepth;
}
int main()
{
string line;
getline(cin, line);
int maxDepth = solveMethod(line);
cout << maxDepth << endl;
return 0;
}