import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv;

void main() {
  char[] s = readln.chomp.to!(char[]);
  char now1 = s[0], now2 = s[$ - 1];
  if (s[0] == s[$ - 1]) {
    ulong cur1, cur2;
    foreach (i, c; s) {
      if (now1 != c) {
        cur1 = i;
        break;
      }
    }
    foreach_reverse (i, c; s) {
      if (now2 != c) {
        cur2 = i;
        break;
      }
    }

    writeln(max(s.length - cur1, cur2 + 1));
  } else {

    ulong cur1, cur2;
    foreach (i, c; s) {
      if (now1 != c) {
        cur1 = i;
        break;
      }
    }
    foreach_reverse (i, c; s) {
      if (now2 != c) {
        cur2 = i;
        break;
      }
    }
    writeln(cur2 - cur1 + 1);
  }
}
