#include <iostream>
#include <string>

using namespace std;

int main() {

    string number;
    getline(cin, number);

    bool appeared[10];
    for(int i = 0; i < 10; i++) {
        appeared[i] = false;
    }
    // 112223332222222
    int numOfChanges = 0;

    for(long long unsigned i = 0; i <= number.size(); i++) {
        if(!appeared[number[i] - '0']) {
            appeared[number[i] - '0'] = true;
        }
        else {
            if(number[i] != number[i - 1]) {

                //appeared[number[i - 1] - '0'] = false;

                long long unsigned forward = i, back = i - 1;
                //int changesFor = 0, changesBack = 0;
                while(number[forward] == number[i] && number[back] == number[i - 1]) {
                    back--;
                    forward++;
                    if(back < 0 || forward >= number.size()) {
                        break;
                    }
                }
                if(number[back] == number[i - 1] || forward >= number.size()) {
                    for(int j = i; j <= forward; j++) {
                        number[j] = number[i];
                        numOfChanges++;
                    }
                }
                else if(number[forward] == number[i] || back < 0) {
                    for(int j = back; j <= i - 1; j++) {
                        number[j] = number[i];
                        numOfChanges++;
                    }
                }
            }
        }
    }
    if(numOfChanges) {
        cout << numOfChanges - 1 << endl;
    }
    else {
        cout << numOfChanges << endl;
    }
return 0;
}