s = input() if len(s)==1: print(-1) else: n = len(s) a = s[:(n+1)//2] b = s[::-1][:(n+1)//2] if sum([s[0]==s[i]for i in range(n)])==n and a==b: print(0) elif a==b: print(n-2) else: print(n)