#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 50 + 5;
const int MAX_M = 400 + 5;
int n;
char str[MAX_N];
int f[2][MAX_N][MAX_M][MAX_M];

bool in_border(int x, int y) {
    x += 200; y += 200;
    return x >= 0 && y >= 0 && x < MAX_M && y < MAX_M;
}

void dfs(int dir, int i, int lazy, int rem) {
    int &F = f[dir < 0][i][lazy + 200][rem + 200];
    if (F >= 0) return ;
    if (i == n) {
        F = rem ? 0x3f3f3f3f : 0;
        return ;
    }
    F = 0x3f3f3f3f;
    const int cur = str[i] - lazy + rem * 10;
    if (in_border(lazy, cur)) {
        dfs(1, i + 1, lazy, cur);
        dfs(-1, i + 1, lazy, cur);
        F = min(f[0][i + 1][lazy + 200][cur + 200], f[1][i + 1][lazy + 200][cur + 200]);
    }
    if (in_border(lazy + dir, rem)) {
        dfs(dir, i, lazy + dir, rem);
        F = min(F, f[dir < 0][i][lazy + dir + 200][rem + 200] + n - i);
    }
}

int main() {
    scanf("%s", str + 1);
    str[0] = 48;
    n = strlen(str);
    for (int i = 0; i < n; i ++) str[i] ^= 48;
    memset(f, -1, sizeof(f));
    dfs(1, 0, 0, 0);
    printf("%d\n", f[0][0][200][200]);
    return 0;
}