def is_palindrome(s): n = len(s) for i in range(n // 2): if s[i] != s[n - 1 - i]: return False return True def all_same(s): if not s: return True c = s[0] for char in s: if char != c: return False return True s = input().strip() n = len(s) if not is_palindrome(s): print(n) else: if all_same(s): if n % 2 == 0: print(0) else: print(-1) else: print(n - 2)