s = list(map(str,input())) ans = len(s) elem = set() flag = True for i in range(ans//2): if(s[i] != s[ans-1-i]): flag = False break else: elem.add(s[i]) if(ans % 2 != 0): elem.add(s[i+1]) if(flag): if(len(elem) == 1): if(ans % 2 == 0): print(0) else: print(-1) else: print(ans - 2) else: print(ans)