#include <iostream>
#include <vector>

using namespace std;



int main()
{
    long long int x;
    int i = 0, p, k, pos, u = 0;
    short int q;
    cin>>x;

    while(x > 0)
    {
        x /= 10;
        i++;
    }
    vector<short int> a(i);
    for(int j = 0; j < i;j++)
    {
        a[i-j-1] = x%10;
        x /= 10;
    }


    for(int j = 0;j < i; j++ )
    {
        p = 0;
        for(k = j+1; k < i; k++)
        {
            if(a[j] == a[k])
            {
                p++;
                pos = k;
            }
        }

        if(p != 0)
        {
            for(p = j+1;p < pos;p++)
            {
                a[p] = a[j];
                u++;
            }

    }
    }
    cout<<u;


}