from collections import Counter S = str(input()) N = len(S) if N == 1: print(-1) exit() ls = list(S) cs = Counter(ls) if len(cs) == 1: if N%2 == 0: print(0) else: print(-1) else: if S[:N//2] != S[N-1:N//2:-1]: print(N) else: if N == 3: print(-1) else: print(N-2)