#include <bits/stdc++.h>

using namespace std;

const int N = 2e5;
vector<int> a(N);
int n;

bool ok(int x) {
    vector<int> u(10);
    bool f = false;
    for (int i = x; i; i /= 10) {
        f |= (i % 10 == 0);
    }
    if (f && x < round(pow(10, n - 1))) {
        return false;
    }
    int p = -1;
    while (x) {
        if (x % 10 == p) {
            x /= 10; continue;
        }
        if (u[x % 10]) {
            return false;
        }
        u[x % 10] = 1;
        p = x % 10; x /= 10;
    }
}

int calc(int x) {
    int c = 0;
    for (int i = n - 1; i >= 0; i--) {
        c += (a[i] != x % 10);
        x /= 10;
    }
    return c;
}

void sol1() {
    int r = 7;
    for (int i = 0; i <= 1e6; i++) {
        if (ok(i)) {
            r = min(r, calc(i));
        }
    }
    cout << r << endl;
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }
    if (n <= 6) {
        sol1();
    }
    return 0;
}