#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3;

int n,a[N];
int dp[N][(1<<10)];

int malin(){  ///n^2*(2^10)*10 -> n <= 100 tj. br < 10^100
    for(int i = 0; i <= n; i++){
        for(int mask = 0; mask < (1<<10); mask++){
            dp[i][mask] = N;
        }
    }
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int mask = 1; mask < (1<<10); mask++){
            int x = __builtin_popcount(mask);
            //cout << x << endl;
            for(int b = 0; b < 10; b++){
                if(!((1<<b)&mask)) continue;
                int br = 0;
                for(int j = i; j > x-1; j--){
                    if(a[j] != b) br++;
                    dp[i][mask] = min(dp[i][mask],dp[j-1][mask^(1<<b)]+br);
                }
            }
            //cout << i << " " << mask << " " << dp[i][mask] << endl;
        }
    }
    int sol = N;
    for(int mask = 1; mask < (1<<10); mask++){
        sol = min(sol,dp[n][mask]);
    }
    return sol;
}

int subtask2(){
    ll ukbr0 = 0,ukbr1 = 0;
    for(int i = 1; i <= n; i++){
        ukbr1 += (a[i] == 1);
        ukbr0 += (a[i] == 0);
    }

    ll sol = N;
    ll pf0 = 0,pf1 = 0;
    for(int i = 0; i <= n; i++){
        if(i > 0){
            pf0 += (a[i] == 0);
            pf1 += (a[i] == 1);
        }
        /// do i idu nule
        sol = min(sol,pf1+(ukbr0-pf0));
        /// do i idu kecevi
        sol = min(sol,pf0+(ukbr1-pf1));
    }
    return sol;
}

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

    if(n <= 100){
        cout << malin() << endl;
        return 0;
    }

    bool drugi = 1;
    for(int i = 1; i <= n; i++){
        if(a[i] != 0 && a[i] != 1){
            drugi = 0;
        }
    }
    if(drugi){
        cout << subtask2() << endl;
        return 0;
    }
}