def is_palindrome(s): left = 0 right = len(s) - 1 while left < right: if s[left] != s[right]: return False left += 1 right -= 1 return True def all_same(s): if not s: return True first = s[0] for c in s: if c != first: return False return True s = input().strip() if not is_palindrome(s): print(len(s)) else: if all_same(s): if len(s) % 2 == 0: print(0) else: print(-1) else: print(len(s) - 2)