#include <bits/stdc++.h>
#include <bits/stdtr1c++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define endl "\n"
#define amfetamin ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const int N = 1e5 + 5;
bool proveri(string s)
{
    bool b[10] = { };
    b[s[0] - '0'] = true;
    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] != s[i - 1] && b[s[i] - '0'] == true)
            return 0;
        b[s[i] - '0'] = true;
    }
    return 1;
}
int raz(string a, string b)
{
    int ret = 0;
    for (int i = 0; i < a.size(); i++)
        if (a[i] != b[i])
        ret++;
    return ret;
}
int main()
{
amfetamin;
string s;
cin >> s;
if (s == "1000000")
{
    cout << 0;
    return 0;
}
if (s.size()<7)
{
    int sol = 6;
    string lim = "";

    for (int i = 0; i < s.size(); i++)
        lim += "9";
    int l = stoi(lim);
    for (int i = 0; i <= l; i++)
    {
        string sm = to_string(i);
        string si = "";
        for (int j = 0; j < s.size() - sm.size(); j++)
            si += "0";
        si += sm;
        bool b = proveri(si);
        if (b)
        {
            int cur = raz(s, si);
            sol = min(sol, cur);
        }
    }
    cout << sol;
    return 0;
}
int n = s.size();
int sol = n;
int pref[n][2] = { };
pref[0][s[0] - '0']++;
for (int i = 1; i < n; i++)
{
    pref[i][0] = pref[i - 1][0];
    pref[i][1] = pref[i - 1][1];
    pref[i][s[i] - '0']++;
}
for (int i = 0; i < n; i++)
{
    int cur = (pref[n - 1][0] - pref[i][0]) + pref[i][1];
    sol = min(sol, cur);
}
for (int i = 0; i < n; i++)
{
    int cur = (pref[n - 1][1] - pref[i][1]) + pref[i][0];
    sol = min(sol, cur);
}
cout << sol;



}