#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define N 505
using namespace std;
int f[52][95][905][2],n,mx=450,cc=45;
char s[N];
int calc(int x,int cur,int res,int op){
	if(x==n+1&&!cur)return 0;
	if(abs(cur)>cc||abs(res)>mx||x==n+1)return 0x3f3f3f3f;
	if(~f[x][cur+cc][res+mx][op==1])return f[x][cur+cc][res+mx][op==1];
	f[x][cur+cc][res+mx][op==1]=min(calc(x,cur,res+op,op)+n-x+1,min(calc(x+1,cur*10+s[x+1]-'0'-res,res,1),calc(x+1,cur*10+s[x+1]-'0'-res,res,-1)));
	return f[x][cur+cc][res+mx][op==1];
}
int main(){
	scanf("%s",s+2);n=strlen(s+2);s[1]='0';
	memset(f,~0,sizeof(f));
	printf("%d\n",calc(0,0,0,1));
	return 0;
} 
/*
*/