local s = io.read() local allsame = true local n = #s for i = 2, n do if s:byte(1) ~= s:byte(i) then allsame = false break end end local pali = true for i = 1, n do local j = n + 1 - i if i < j then if s:byte(i) ~= s:byte(j) then pali = false break end else break end end if allsame then print(n % 2 == 0 and 0 or -1) else if pali then print(n == 3 and -1 or n - 2) else print(n) end end