s = input() if len(set(s)) == 1: if len(s) % 2 == 1: print(-1) else: print(0) else: if s != s[::-1]: print(len(s)) else: print(len(s) - 2)