#include<bits/stdc++.h>

using namespace std;

main()
{
    int brojac=0,b,i=0,brojac1=0;
    long int n;
    cin>>n;
    int a=n;
    while(a!=0)
    {
        a=a/10;
        brojac++;
    }
    int x[brojac];
    while(n!=0)
    {
        b=n%10;
        n=n/10;
        x[i]=b;
        i++;
    }
    if(brojac==3)
    {
        if(x[0]==x[1] || x[1]==x[2])
            cout<<0<<endl;
        else
            cout<<1<<endl;
    }else
    {


    int y[brojac];
    for(int i=0;i<brojac;i++)
    {
        y[brojac-1-i]=x[i];
    }
    int z[brojac-3];
    for(int i=0;i<brojac-3;i++)
    {
        if(y[i]!=y[i+1])
            brojac1++;
        if(y[i+2]!=y[i+3])
            brojac1++;
        z[i]=brojac1;
        brojac1=0;
    }
    int m=z[0];
    for(int i=1;i<brojac-3;i++)
    {
        if(z[i]<=m)
            m=z[i];
    }
    cout<<m<<endl;
    }
}