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>
// #define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf (int)(1e8)
#define md (int)(1e9+7)
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;

const int M = 50 + 11;
const int K = 251;

int n;
string s;
int dp[2][M][K][K];
/*
int f(int i,int car,int pos,int neg) {
	if(pos<0 or neg<0 or car+30>=M or car+30<0) return inf;
	if(i>=n) return car?inf:0;
	if(dp[i][car+30][pos][neg]!=-1) return dp[i][car+30][pos][neg];
	int ans=min(f(i,car,pos-1,neg),f(i,car,pos,neg-1));
	int now=s[i]-'0',tot=pos-neg+car;
	if((tot%10+10)%10==now) {
		ans=min(ans,f(i+1,tot/10+(tot>0?0:-1)*(bool)(tot%10),pos,neg)+pos+neg);
	}
	return dp[i][car+30][pos][neg]=ans;
}
*/
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   	
   	cin>>s;
   	reverse(all(s));
   	s+="0";
   	n=sz(s);
   	rep(i,0,2)rep(car,0,M)rep(pos,0,K)rep(neg,0,K) dp[i][car][pos][neg]=inf;
  	rep(pos,0,K)rep(neg,0,K) dp[0][0+M/2][pos][neg]=0;
  	for(int i=n-1;i>=0;--i) {
  		rep(car,-M/2,M/2+1)rep(pos,0,K)rep(neg,0,K) {
  			int &ans=dp[1][car+M/2][pos][neg];
  			if(pos) ans=min(ans,dp[1][car+M/2][pos-1][neg]);
  			if(neg) ans=min(ans,dp[1][car+M/2][pos][neg-1]);
  			int now=s[i]-'0',tot=pos-neg+car;
  			if((tot%10+10)%10==now) {
  				int ncar=tot/10+(tot>0?0:-1)*(bool)(tot%10)+M/2;
  				if(ncar<0 or ncar>=M) continue;
  				ans=min(ans,dp[0][ncar][pos][neg]+pos+neg);
  			}
  		}
  		rep(car,-M/2,M/2+1)rep(pos,0,K)rep(neg,0,K) {
  			dp[0][car+M/2][pos][neg]=dp[1][car+M/2][pos][neg];
  			dp[1][car+M/2][pos][neg]=inf;
  		}
  	}
  	cout<<dp[0][0+M/2][K-1][K-1];
  	/*
   	memset(dp,-1,sizeof(dp));
   	cout<<f(0,0,K-1,K-1);
   	*/
   	
    return 0;
}