#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

vi a;
string s;
int f(int ind, int j){
    return (a[ind] != j);
}

int solve(){
    int n = s.length();
    vi cnt(n, 0);
    if (a[0] == 1)
        ++cnt[0];

    for (int i = 1; i < n; ++i){
        cnt[i] = cnt[i-1] + a[i]; 
    }

    int sol = min(cnt[n-1], n - cnt[n-1]);
    for (int i = 0; i < n; ++i){
        //neka je i poslednji kec
        sol = min(sol, i+1-cnt[i] + cnt[n-1]-cnt[i]);

        //neka je i poslednja 0
        sol = min(sol, cnt[i] + n-i-1 - (cnt[n-1]-cnt[i]));
    }

    return sol;
}

int d[1024][10], dp_new[1024][10];

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);  
    for (int i = 0; i < 1024; ++i)
        for (int j = 0; j < 10; ++j)
            d[i][j] = dp_new[i][j] = INT32_MAX/5;

    cin >> s;;
    bool jedan = 1;
    for (auto& i : s){
        a.push_back(i-'0');
        if (a.back() > 1){
            jedan = 0;
        }
    }

    if (jedan){
        return cout << solve() << '\n', 0;
    }

    int n = s.length();
 //   vector<vector<vi>> dp(n, vector<vi>(1024, vi(10, INT32_MAX/5)));

    for (int i = 0; i < 10; ++i){
   //     dp[0][1 << i][i] = f(0, i);     
        d[1 << i][i] = f(0, i);     
    }

    for (int i = 1; i < n; ++i){
        for (int mask = 0; mask < 1024; ++mask){
            for (int j = 0; j < 10; ++j){
                dp_new[mask][j] = INT32_MAX/5;
                if (!(mask & (1 << j))) continue;

                //dp[i][mask][j] = min(f(i, j) + dp[i-1][mask][j], dp[i][mask][j]);
                dp_new[mask][j] = min(f(i, j) + d[mask][j], dp_new[mask][j]);
                //if (dp[i][mask][j] != dp_new[mask][j])
                  //  return cout << "ZZVONI", 0;

                for (int k = 0; k < 10; ++k){
                  //  dp[i][mask][j] = min(dp[i-1][mask^(1 << j)][k] + f(i, j), dp[i][mask][j]);
                    dp_new[mask][j] = min(d[mask^(1 << j)][k] + f(i, j), dp_new[mask][j]);
                }

                //if (dp[i][mask][j] != dp_new[mask][j])
                  //  return cout << "ALO", 0;
            }
        }
        for (int mask = 0; mask < 1024; ++mask)
            for (int j = 0; j < 10; ++j)
                d[mask][j] = dp_new[mask][j];
    }

    int sol = n, res = n;
    for (int mask = 0; mask < 1024; ++mask){
        for (int j = 0; j < 10; ++j){
            //sol = min(sol, dp[n-1][mask][j]);
            res = min(res, d[mask][j]);
        }
    }

    cout << res << '\n';
}