from collections import Counter s = list(input()) c = Counter(s) if len(c) == 1: if len(s) & 1: print(-1) else: print(0) elif s != s[::-1]: print(len(s)) else: if len(s) == 3: ptint(-1) else: print(len(s)-2)