s = input().strip() # Function to check if the string is a palindrome def is_palindrome(s): return s == s[::-1] if not is_palindrome(s): print(len(s)) else: # Check if all characters are the same all_same = all(c == s[0] for c in s) if all_same: if len(s) % 2 == 0: print(0) else: print(-1) else: if len(s) == 1: print(-1) else: print(len(s) - 2)