import sys INF = float('inf') #10**20,2**63,float('inf') MOD = 10**9 + 7 MOD2 = 998244353 from collections import defaultdict def solve(): def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LC(): return list(input()) def IC(): return [int(c) for c in input()] def MI(): return map(int, sys.stdin.readline().split()) S = LC() N = len(S) C = defaultdict(lambda:0) Flag = True if N==3: if (S[0] == S[2]) and S[0] != S[1]: print(-1) exit() for n in range(N): C[S[n]] = 1 if(S[n] != S[N-n-1]): Flag = False if not Flag: print(N) exit() #以下は回文 if sum(list(C.values())) >=2:#2文字以上使われてたら,元の長さから良い感じに2個消せばいい. print(N-2) exit() #以下は使われる文字が1種類 if N%2 == 1: print(-1) else: print(0) return solve() #sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!