import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); char[] s = sc.next().toCharArray(); sc.close(); int n = s.length; boolean all = true; boolean kai = true; for (int i = 0; i < n; i++) { if (s[0] != s[i]) { all = false; } if (s[i] != s[n - 1 - i]) { kai = false; } } if (!kai) { System.out.println(n); return; } if (all) { if (n % 2 == 0) { System.out.println(0); } else { System.out.println(-1); } } else { System.out.println(n - 2); } } }