#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
using namespace std;
#define ll long long
#define ri register int

const int N = 251;
const int M = 28;

string s;
int n;
int dp[2][M*3][N+10][N+10];

signed main() {
    cin >> s;
    reverse(s.begin(),s.end());
    s += "0";
    n = s.size();
    memset(dp[0],0x3f,sizeof dp[0]);
    dp[0][M][N-1][N-1] = 0;
    
    for (int i = 0;i < n;++i) {
        memset(dp[1],0x3f,sizeof dp[1]);
        for (int j = 0;j < M*2+1;++j) {
            for (int up = N-1;up >= 0;--up) {
                for (int down = N-1;down >= 0;--down) {
                    if (dp[0][j][up][down] != 0x3f3f3f3f) {
                        if (up > 0) dp[0][j][up-1][down] = min(dp[0][j][up-1][down],dp[0][j][up][down]);
                        if (down > 0) dp[0][j][up][down-1] = min(dp[0][j][up][down-1],dp[0][j][up][down]);
                        int now = j - M;
                        int dig = (now + up - down) % 10;
                        if (dig < 0) dig += 10;
                        int tim = (now + up - down) / 10;
                        if ((now + up - down) < 0 && dig != 0) --tim;
                        if (dig == s[i] - '0') {
                            dp[1][tim+M][up][down] = min(dp[1][tim+M][up][down],dp[0][j][up][down] + up + down);
                        }
                    }
                }
            }
        }
        swap(dp[0],dp[1]);
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0;i < N;++i) {
        for (int j = 0;j < N;++j) {
            ans = min(ans,dp[0][M][i][j]);
        }
    }
    printf("%d",ans);
}