s = input() n = len(s) a = s[0 : n // 2] b = s[(n + 1) // 2 : n][::-1] if a != b: print(n) elif len(set(list(a))) != 1: print(n - 2) elif n % 2 == 0: print(0) else: print(-1)