#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define pb push_back
#define x first
#define y second
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

string s;
int sol;

bool check(int x, int n) {
    int prev = -1, flag = 1;
    sol = 0;
    vector<int> a(10, 0);
    while (n--) {
        int tmp = x % 10;
        if (tmp != prev) {
            if (a[tmp]) {
                flag = 0;
                break;
            }
            a[tmp] = 1;
            prev = tmp;
        }
        x /= 10;
        int cur = int(s[n]) - int('0');
        if (tmp != cur) sol++;
    }
    return flag;
}

int main()
{
    IOS;
    cin >> s;
    int n = s.length();
    if (n > 6) {
        vector<int> a(n + 1);
        a[0] = 0;
        for (int i = 0; i < n; i++) {
            a[i + 1] = a[i];
            if (s[i] == '0') a[i + 1]++;
        }
        int ans = n;
        for (int i = 0; i <= n; i++) {
            int tmp1 = a[n] + i - 2 * a[i];
            int tmp2 = 2 * a[i] + n - i - a[n];
            ans = min(ans, min(tmp1, tmp2));
        }
        cout << ans;
    } else {
        int st = 1, ans = n;
        for (int i = 0; i < n; i++) st *= 10;
        for (int i = 0; i < st; i++) {
            if (check(i, n)) ans = min(ans, sol);
        }
        cout << ans;
    }
    return 0;
}