S = list(input()) N = len(S) left, right = 0, N - 1 while left < right: if S[left] != S[right]: print(N) exit() left += 1 right -= 1 if len(set(S)) == 1: if len(S) % 2: print(-1) else: print(0) else: print(N - 2)