S = input() l = len(S) f = 0 for i in range(l): if S[i] != S[l-1-i]: f = 1 break if f == 1: print(l) else: if l == 3: print(-1) elif S.count(S[0]) == l: if l % 2 == 0: print(0) else: print(-1) else: print(l-2)