#include<bits/stdc++.h>
using namespace std;
int len,maxx=-1,lon;
string s;
stack<char> ch1,ch2,ch3;
int main(){
cin>>s;
len=s.length();
for(int i=0;i<len;i++){
lon=0;
while(!ch1.empty()){
ch1.pop();
}
while(!ch2.empty()){
ch2.pop();
}
while(!ch3.empty()){
ch3.pop();
}
for(int j=i;j<len;j++){
if(s[j]==')'){
if(ch1.empty())
break;
if(!ch2.empty()&&ch2.top()>ch1.top())
break;
if(!ch3.empty()&&ch3.top()>ch1.top())
break;
}
if(s[j]==']'){
if(ch2.empty())
break;
if(!ch1.empty()&&ch1.top()>ch2.top())
break;
if(!ch3.empty()&&ch3.top()>ch2.top())
break;
}
if(s[j]=='}'){
if(ch3.empty())
break;
if(!ch2.empty()&&ch2.top()>ch3.top())
break;
if(!ch1.empty()&&ch1.top()>ch3.top())
break;
}
if(s[j]=='(')
ch1.push(j);
if(s[j]==')')
ch1.pop();
if(s[j]=='[')
ch2.push(j);
if(s[j]==']')
ch2.pop();
if(s[j]=='{')
ch3.push(j);
if(s[j]=='}')
ch3.pop();
if(ch1.empty()&&ch2.empty()&&ch3.empty())
lon=j-i+1;
}
maxx=max(maxx,lon);
}
cout<<maxx;
return 0;
}