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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
inline int read_int(){
	int t=0;bool sign=false;char c=getchar();
	while(!isdigit(c)){sign|=c=='-';c=getchar();}
	while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
	return sign?-t:t;
}
inline LL read_LL(){
	LL t=0;bool sign=false;char c=getchar();
	while(!isdigit(c)){sign|=c=='-';c=getchar();}
	while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
	return sign?-t:t;
}
inline char get_char(){
	char c=getchar();
	while(c==' '||c=='\n'||c=='\r')c=getchar();
	return c;
}
inline void write(LL x){
	char c[21],len=0;
	if(!x)return putchar('0'),void();
	if(x<0)x=-x,putchar('-');
	while(x)c[++len]=x%10,x/=10;
	while(len)putchar(c[len--]+48);
}
inline void space(LL x){write(x),putchar(' ');}
inline void enter(LL x){write(x),putchar('\n');}
const int MAXN=55,MAXV=30,MAXC=255,Inf=1e9;
int a[MAXN],dp[2][MAXV<<1|1][MAXC][MAXC];
char s[MAXN];
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%s",s);
	int n=strlen(s),pos=0;
	_for(i,0,n)a[i]=s[n-i-1]-'0';
	a[n++]=0;
	_for(i,0,MAXV<<1|1)_for(j,0,MAXC)_for(k,0,MAXC)dp[pos][i][j][k]=Inf;
	dp[pos][MAXV][MAXC-1][MAXC-1]=0;
	_for(p,0,n){
		pos=!pos;
		_for(i,0,MAXV<<1|1)_for(j,0,MAXC)_for(k,0,MAXC)dp[pos][i][j][k]=Inf;
		_for(i,0,MAXV<<1|1)for(int j=MAXC-1;j>=0;j--)for(int k=MAXC-1;k>=0;k--){
			if(j)dp[!pos][i][j-1][k]=min(dp[!pos][i][j-1][k],dp[!pos][i][j][k]);
			if(k)dp[!pos][i][j][k-1]=min(dp[!pos][i][j][k-1],dp[!pos][i][j][k]);
			if(dp[!pos][i][j][k]==Inf)continue;
			int i2=i-MAXV;
			if((i2+j-k-a[p])%10==0){
				int next_i=(i2+j-k-a[p])/10+MAXV;
				dp[pos][next_i][j][k]=min(dp[pos][next_i][j][k],dp[!pos][i][j][k]+j+k);
			}
		}
	}
	int ans=Inf;
	_for(i,0,MAXC)_for(j,0,MAXC)ans=min(ans,dp[pos][MAXV][i][j]);
	enter(ans);
	return 0;
}
