S=input() C=set(S) if S!=S[::-1]: print(len(S)) elif len(C)==1: if len(S)%2==0: print(0) else: print(-1) elif len(S)==3: print(-1) else: print(len(S)-2)