#include<bits/stdc++.h>

using namespace std;

main()
{
    int brojac=0,b,i=0,brojac1=0,m=0,brojac2=0,brojac3=0;
    long long int n;
    cin>>n;
    int a=n;
    while(a!=0)
    {
        a=a/10;
        brojac++;
    }
    int x[brojac],mi=brojac;
    while(n!=0)
    {
        b=n%10;
        n=n/10;
        x[i]=b;
        i++;
    }
    int k=x[0];
    for(int i=0;i<brojac;i++)
    {
        for(int j=i+1;j<brojac;j++)
        {
            if(x[i]==x[j])
                if(i+1!=j)
                    brojac1++;
                else
                    brojac2++;

        }
        if(brojac1>=m)
            m=brojac1;
        brojac1=0;
        if(brojac2<mi)
            mi=brojac2;
        brojac2=0;

    }
    cout<<m-mi<<endl;
}