#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    string T;
    unordered_map<char,int> count1,count2;
    cin >> T;
    int n = T.length();//T[n-1] je poslednji character
    int i = 0;/////////////prvi
    while(T[n-1-i] == T[i] && i != n-1-i) i++;
    if(i == n-i)
    {
        cout << 1;
        return 0;
    }
    for(int j = i; j < n-1-i; j++)
    {
        count1[T[j]]++;
        count2[T[j]]++;
    }
    int j = n-1-i;////////poslednji
    int pomi = i,pomj = j, raz1, raz2;
    while(count1[T[i]]-1 > 0)
    {
        count1[T[i]]--;
        i++;
    }
    raz1 = j - i + 1;
    while(count2[T[pomj]]-1 > 0)
    {
        count2[T[pomj]]--;
        pomj--;
    }
    raz2 = pomj - pomi + 1;
    cout << min(raz1, raz2);
}