s=input() n=len(s) if s!=s[::-1]: print(n) elif len(set(list(s)))==1: print([0,-1][n%2]) else: print([-1,n-2][n>3])