void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.array;
  
  auto s=readln.chomp.to!(char[]);

  int maxLen(char[] str){
    auto n=str.length;
    bool enough(char[] s, int w){
      // writeln(w, " ", s);
      for(auto r=0, l=0, f=false; r<n; r++){
        if(s[r]=='0') l=r, f=false;
        else if(f) s[r]='0';
        else if(r-l==w){
          f=true;
          for(auto j=l+1; j<=r; j++) s[j]='0'; 
        }
      }
      // writeln(w, " ", s);
      auto sub=new int[](n+1);
      for(auto i=0; i+w<n; i++){
        auto cur=s[i]-'0';
        if(sub[i]&1) cur^=1;
        if(cur) sub[i]++, sub[i+w]--;
        sub[i+1]+=sub[i];
      }
      bool zero=true, one=true;
      for(auto i=n-w; i<n; i++){
        auto cur=s[i]-'0';
        if(sub[i]&1) cur^=1;
        zero&=(cur==0);
        one&=(cur==1);
        // if(w==3) write(cur, " ");
        sub[i+1]+=sub[i];
      }
      // writeln();
      return (zero || one);
    }
    int ok=1, ng=to!int(n)+1;
    while(ng-ok>1){
      auto m=(ng+ok)/2;
      // writeln(m);
      enough(str.dup, m) ? ok : ng = m;
    }
    // writeln();
    return ok;
  }

  auto t=map!(c=>(c=='0'?'1':'0'))(s).array;
  writeln(max(maxLen(s.dup), maxLen(t.dup)));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}
