You are given a positive (greater than zero) integer n.

You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 + 11 + 1 + 1 and 102 = 111 - 11 + 1 + 1. 

Among all possible representations, you have to find the one that uses the minimum number of ones in total.

Input

The single line contains one integer n (1 ≤ n < 10^{50}).

Output

Print one integer x — the minimum number of ones, such that there exist a representation of n as the sum of integers (possibly negative) that uses x ones in total.

Examples

Input


24


Output


6


Input


102


Output


7
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 1000000010
const int N = 250 ;
const int M = 65 ;



int n;

string s;


int dp[2][N][N][2 * M];



int main(){

	cin >> s;
	reverse(s.begin(),s.end());

	s += "000";
	n = (int)s.size();


	for(int a = 0 ; a < N;a++){
		for(int b = 0 ; b < N;b++){
			for(int i = 0 ;i < 2 * M;i++){
				if(i != M)
					dp[n & 1][a][b][i] = oo;
			}
		}
	}

	for(int cur , i = n - 1;i >= 0;i--){
		cur = (i & 1);
		for(int a = 0 ; a < N;a++){
			for(int b = 0 ;b < N;b++){
				for(int j = 0 ;j < 2 * M;j++){
						dp[cur][a][b][j] = oo;
						//if((((s[i] - '0') + a + j - b - M) / 10) <= -M || (((s[i] - '0') + a + j - b - M) / 10) >= M) continue;
						if(((s[i] - '0') + a + j - b - M) % 10 == 0)
							dp[cur][a][b][j] = a + b + dp[cur ^ 1][a][b][(((s[i] - '0') + a + j - b - M) / 10) + M];
						if(a > 0)
							dp[cur][a][b][j] = min(dp[cur][a][b][j] , dp[cur][a - 1][b][j]);
						if(b > 0)
							dp[cur][a][b][j] = min(dp[cur][a][b][j] , dp[cur][a][b - 1][j]);
				}
			}
		}
	}
	int ans = oo;
	for(int i = 0 ;i < N;i++){
		for(int j = 0 ;j < N;j++){
			ans = min(ans , dp[0][i][j][M]);
		}
	}
	cout << ans << endl;
	
	return 0;
}