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