#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main(){
        std::string unos;
        std::vector<int> count(123);    // 'a' = 97, 'z' = 122
        int promenljiva = -12121;

        std::cin >> unos;
        int last = unos.length();
        for (int i = 0; i < last; i++){
                count[unos[i]]++;
        }

        for (int i = 0; i < ceil(last/2); i++){
                if (!(unos[i]==unos[last-i-1])){
                        promenljiva = i;
                        break;
                }
                count[unos[i]]--;
                count[unos[i]]--;
        }

        if ((last % 2 == 1) && (promenljiva == -12121)){
                count[unos[ceil(last/2)]]--;
                promenljiva = ceil(last/2);
        }


        std::vector<int> count_copy = count;
        int levoduzina, desnoduzina;

        //Probam da skratim podstring sleva
        for (int i = promenljiva; true; i++){
                if (count_copy[unos[i]] <= (count[unos[i]] - count_copy[unos[i]])){
                        levoduzina = last - promenljiva - i;
                        break;
                }
                count_copy[unos[i]]--;
        }
        
        count_copy = count;
        //Probam da skratim podstring sdesna
        for (int i = last-promenljiva-1; true; i--){
                if (count_copy[unos[i]] <= (count[unos[i]] - count_copy[unos[i]])){
                    desnoduzina = i - promenljiva + 1;
                    break;
                }
                count_copy[unos[i]]--;
        }
        
        if (levoduzina > desnoduzina){          // Ovo sam uradio jer je u svakom mom test primeru tacna dužina bila veca i inace bih morao da menjam uslov gore
            std::cout << levoduzina;
        } else {
            std::cout << desnoduzina;
        }
}