s = input() n = len(s) ans = n if s != s[::-1] else n - 2 if len(set(s)) >= 2 and n >= 4 else 0 if n % 2 == 0 else -1 print(ans)