def is_palindrome(s): return s == s[::-1] S = input().strip() if not is_palindrome(S): print(len(S)) else: all_same = all(c == S[0] for c in S) if all_same: if len(S) % 2 == 0: print(0) else: print(-1) else: print(len(S) - 2)