#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
int solve(string s){
	int cs=0,mi=0,ans=0;
	set<int> S;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1')cs++;
		else cs--;
		chmin(mi,cs);
		if(ans<cs-mi){
			S.clear();
			ans=cs-mi;
		}
		if(ans==cs-mi){
			S.insert(i%2);
		}
	}
	if(S.size()==2)ans++;
	return ans;
}
int main(){
	string s;
	cin>>s;
	if(s.size()==1){
		cout<<1<<endl;
		return 0;
	}
	int a=solve(s);
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')s[i]='1';
		else if(s[i]=='1')s[i]='0';
	}
	int b=solve(s);
	//cout<<a<<" "<<b<<endl;
	cout<<max(a,b)<<endl;
}
