#!/usr/bin/env python3
# from typing import *


def solve(s: str) -> int:
    if s != ''.join(reversed(s)):
        return len(s)
    if s == s[0] * len(s):
        if len(s) % 2 == 0:
            return 0
        else:
            return -1
    return len(s) - 2


# generated by oj-template v4.8.0 (https://github.com/online-judge-tools/template-generator)
def main():
    S = input()
    a = solve(S)
    print(a)


if __name__ == '__main__':
    main()