#include <bits/stdc++.h>

using namespace std;
bool dis[100007];
int am[10];
bool jk[10];
pair<int, int> rn[10];

bool by_difference(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second-a.first)<(b.second-b.first) ||
    (a.second == -1 && a.first == -1 && b.first != -1 && b.second != -1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s, tmp;
    cin >> s;
    tmp = s;
    int sl = s.length();
    // 756030024510330
    for (int cr = 0; cr <= 9; cr++) {
        if (jk[cr]) continue;
        for (int i = 0; i < 10; i++) {
            rn[i] = {-1, -1};
            am[i] = 0;
        }
        for (int expr = 0; expr <= 9; expr++) {
            int tmpi = -1, tmpj = -1;
            for (int i = 0; i < sl; i++) {
                    if (dis[i] || jk[s[i] - '0']) {
                        if (tmpi != -1) {
                            if (tmpj-tmpi >= rn[expr].second - rn[expr].first) {
                                rn[expr].second = tmpj;
                                rn[expr].first = tmpi;
                            }
                            tmpi = -1;
                        }
                        am[expr] = 0;
                        continue;
                    }
                    if (s[i] == '0'+expr) {
                        if (i) {
                            if ((s[i-1] != ('0'+expr)))
                                am[expr] = 0;
                        }
                        if (am[expr] == 0 && tmpi == -1) {
                            tmpi = i;
                        }
                        tmpj = i;
                        am[expr] += 1;
                    } else {
                        if (am[expr] == ((tmpj-tmpi==0)? 0 : 1)) {
                            if (tmpi != -1) {

                                if (tmpj-tmpi > rn[expr].second - rn[expr].first) {
                                    rn[expr].second = tmpj;
                                    rn[expr].first = tmpi;
                                }
                                tmpi = -1;
                            }
                        }
                        am[expr] = max(0, am[expr] - 1);
                    }
                if (i == sl - 1) {
                    if (tmpi != -1) {
                        if (tmpj-tmpi >= rn[expr].second - rn[expr].first) {
                            rn[expr].second = tmpj;
                            rn[expr].first = tmpi;
                        }
                        tmpi = -1;
                    }
                }
            }
        }
        auto it = max_element(rn, rn+10, by_difference);
        pair<int, int> mx = *it;
        int num = it-rn;
        for (int i = mx.first; i <= mx.second; i++) {
            dis[i] = true;
            s[i] = num+'0';
        }
        jk[num] = true;

    }
    int cnt = 0;
    for (int i = 0; i < sl; i++) {
        if ((s[i] != tmp[i]) || (jk[s[i] - '0'] && !dis[i])) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}