S = input() if S!=S[::-1]: print(len(S)) exit() for i in range(len(S)-1): if S[i]!=S[i+1]: if len(S)==3: print(-1) exit() else: print(len(S)-2) exit() if len(S)%2==1: print(-1) else: print(0)