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