#include int main() { char s[1000006]; scanf("%s", s); int i, n = 0; while (s[n] != '\0') n++; int cnt = 0; for (i = 0; i < n / 2; i++) if (s[i] != s[n - i - 1]) cnt++; if (cnt > 0) { printf("%d\n", n); return 0; } for (i = 0; i < n / 2; i++) if (s[i] != s[0]) cnt++; if (cnt > 0) printf("%d\n", n - 2); else if (n % 2 > 0) printf("-1\n"); else printf("0\n"); return 0; }