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