s = input().rstrip() if s==s[::-1]: print(len(s)) elif len(set(s))>1: print(len(s)-2) elif len(s)%2==0: print(0) else: print(-1)