#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mk make_pair
#define v_sort(x) sort(x.begin(),x.end())
#define v_gsort(x) sort(x.begin(),x.end(),greater<ll>())
#define v_find(x,num) find(x.begin(),x.end(),num)
#define PI 3.14159265
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18;

using namespace std;

void Solve(){
  string s;
  cin>>s;
  int n=(int)s.size();
  int l=-1,r=-1;
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n-1-i]) {l=i,r=n-1-i;break;}
  }
  if(l==-1) {cout<<"1\n";return;}
  vector<int>ttl(30,0),cur(30,0);
  for(int i=l;i<=r;i++) ttl[s[i]-'a']++;
  int ans=r-l+1;
  for(int i=l;i<r;i++){
    cur[s[i]-'a']++;
//    cout<<cur[s[i]-'a']<<" "<<ttl[s[i]-'a']<<"-->";
    if(cur[s[i]-'a']>ttl[s[i]-'a']/2) {
//      cout<<i<<" "<<r<<'\n';
      ans=min(r-i+1,ans);break;
    }
//    cout<<'\n';
  }
  cur.clear();
  for(int i=r;i>l;i--){
    cur[s[i]-'a']++;
//    cout<<cur[s[i]-'a']<<" "<<ttl[s[i]-'a']<<"-->";
    if(cur[s[i]-'a']>ttl[s[i]-'a']/2) {
//      cout<<l<<" "<<i<<'\n';
      ans=min(i-l+1,ans);break;
    }
//    cout<<'\n';
  }
  cout<<ans<<'\n';
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
//  cin>>t;
  while(t--){
    Solve();
  }
  return 0;
}