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