import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags
import std.regex;     // RegEx

void main()
{
  auto s = readln.chomp, n = s.length;

  auto calc(size_t k)
  {
    auto m1 = s[0..k].matchFirst(r"^(0*)(1*)$");
    if (m1 && m1[2].length + n-k >= k) return true;

    auto m2 = s[0..k].matchFirst(r"^(1*)(0*)$");
    if (m2 && m2[2].length + n-k >= k) return true;

    auto m3 = s[$-k..$].matchFirst(r"^(0*)(1*)$");
    if (m3 && m3[1].length + n-k >= k) return true;

    auto m4 = s[$-k..$].matchFirst(r"^(1*)(0*)$");
    if (m4 && m4[1].length + n-k >= k) return true;

    return false;
  }

  auto bsearch = iota(1, n+1).map!(k => tuple(k, calc(k))).assumeSorted!"a[1]>b[1]";
  writeln(bsearch.lowerBound(tuple(0, false)).back[0]);
}
