S = input() N = len(S) if S != S[::-1]: print(N) exit() if len(set(S)) != 1: print(N - 2) exit() if N % 2 == 0: print(0) else: print(-1)