import * as fs from "fs" type Input = (args: string) => void const main: Input = args => { const input = args.trim().split("\n"); const S = input.shift() const n = S.length let isOdd = n % 2 == 1 ? true : false let flg = true let chars = new Set() for (let i = 0; i < n / 2; i++) { if (S[i] == S[n - i - 1]) { chars.add(S[i]) } else { flg = false } } if (!flg) { console.log(n) } else if (chars.size === 1) { console.log(isOdd ? -1 : 0) } else if (isOdd && n >= 5 || !isOdd) { console.log(n - 2) } else { console.log(-1) } } main(fs.readFileSync('/dev/stdin', 'utf8'));