s = input() print(len(s) if s != s[::-1] else len(s)-2 if any(si != s[0] for si in s) else -1 if len(s)%2 else 0)