#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define CLR(a,b) memset(a,b,sizeof(a,b))
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 100010;
char s[maxn];
int n[maxn];
int num = 0;
int main()
{
    cin>>s;
    int len = strlen(s);

    if(s[0]=='1'){
        for(int i=0;i<len;i++){
            if(s[i]=='1') s[i]='0';
            if(s[i]=='0') s[i]='1';
        }
    }
    int cnt = 1;
    for(int i=1;i<len;i++){
        if(s[i] == s[i-1])
            cnt = cnt+1;
        else{
            n[++num] = cnt;
            cnt = 1;
        }
    }
    n[++num] = cnt;
    int ans = 0;
    for(int i=1;i<=num;i++){
        if(i%2 == 1 && n[i+2]!=0){
            ans = max(ans,min(n[i],n[i+2])+n[i+1]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
