S=input() N=len(S) if S!=S[::-1]: print(N) exit() if len(set(S))==1: print(-(N&1)) exit() if N==3: print(-1) exit() print(N-2)