#include <iostream>
using namespace std;

#define N 100001
int a[N];
bool visited[10];
int resenje;

void bt(int n, int x, int r) {
    if (x == n) {
        bool visited1[10];
        for (int i = 0; i < 10; i++)
            visited1[i] = false;
        for (int i = 0; i < n; i++) {
            if (visited1[i])
                return;
            int c = a[i];
            while (i < n && a[i] == c)
                i++;
            i--;
            visited1[c] = true;
        }
        resenje = min(resenje, r);
        return;

    }
    bt(n, x + 1, r);
    int cif = a[x];
    for (int i = 0; i < 10; i++)
        if (i != cif) {
            a[x] = i;
            bt(n, x + 1, r + 1);
        }
    a[x] = cif;

}

void BT(int n) {
    resenje = 5;
    bt(n, 0, 0);
    cout << resenje;
}

int main()
{
    string s;
    cin >> s;
    int brc = 0;
    for (int i = 0; i < s.size(); i++) {
        a[i] = s[i] - '0';
        if (!visited[a[i]]) {
            visited[a[i]] = true;
            brc++;
        }
    }
    if (s.size() <= 6) {
        BT(s.size());
        return 0;
    }
    if (brc == 1) {
        cout << 0;
        return 0;
    }
   /* if (brc == 2) {
        int x = 10, y;
        for (int i = 0; i < 10; i++) {
            if (visited[i] && x < 10) {
                y = i;
                break;
            }
            if (visited[i]) {
                x = i;
                continue;
            }
        }
        pair<int, int>br[N];
        a[0] = x?br[0].first = 1, br[0].second = 0:br[0].first = 0, br[0].second = 1;
        for (int i = 0; i < s.size(); i++) {
            if (a[i] == x)
                br[.first
            else
                br2++;
        }
        int resenje = min(br1, br2), resenje1 = 0;
        for (int i = 1; i <)
    }
    */
    return 0;
}