#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)v.size()
#define endl "\n"
#define ff first
#define ss second
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll INF=1e29;
const ll MOD=1e9+7;
const ll nxm=2e7+5;
bool c(pair<ll,ll> a,pair<ll,ll> b){    return a.ss>b.ss;    }
bool sgn(ll a){ if(a>=0) return 1 ;return 0;}
void solve()
{
string s;
cin>>s;
ll n=s.size();
ll res=1;
for(ll i=0;i<n;i++)
{
    if(s[i]=='?')
    {
        if(i!=0)
        {
            if(s[i-1]=='0')
                s[i]='1';
            else if(s[i-1]=='1')
                s[i]='0';
        }

    }
}
for(ll i=n-1;i>=0;i--)
{
    if(s[i]=='?')
    {
        if(i!=n-1)
        {
            if(s[i+1]=='0')
                s[i]='1';
            else if(s[i+1]=='1')
                s[i]='0';
        }

    }
}
ll dp[n];
for(ll i=0;i<n;i++)
{
    if(i==0)
        dp[i]=(s[i]=='1');
    else
        dp[i]=dp[i-1]+(s[i]=='1');
}
for(ll i=0;i<n;i++)
{
    for(ll j=i;j<n;j++)
    {
        if(i==0)
        res=max(res,max((dp[j]-0)-((j-i+1)-(dp[j]-0)),((j-i+1)-(dp[j]-0))-(dp[j]-0)));
        else
        res=max(res,max((dp[j]-dp[i-1])-((j-i+1)-(dp[j]-dp[i-1])),((j-i+1)-(dp[j]-dp[i-1]))-(dp[j]-dp[i-1])));

 //       cout<<i<<" "<<j<<" "<<res<<endl;
     //   if(res==5)
       //     break;
    }
}
//cout<<s;
//REP(i,n) cout<<dp[i]<<" ";
//cout<<endl;
cout<<res;
}
int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}


	return 0;
}
