from collections import Counter x = input() if len(x) >= 4: c = Counter(x) if len(c) == 1: print(-(len(x)%2)) else: for i in range(len(x)//2): if x[i] != x[-i-1]: print(len(x)) break else: print(len(x)-2) else: if x[0] == x[-1]: print(-(len(x)%2)) else: print(len(x))