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