#include <bits/stdc++.h>
using namespace std ;
const int N = 510,M = 55,inf = 0x7f7f7f7f ;
int l,f[M][M][N][2],C,X ; char str[N] ;
#define f(pos,c,x,delta) f[pos][c+C][x+X][delta]
inline int dfs(int pos,int c,int x,int delta){
	if(pos == l) return c ? inf : 0 ;
	if(c > C || c < -C || x > X || x < -X) return inf ; 
	if(f(pos,c,x,delta) != -1) return f(pos,c,x,delta) ;
	f(pos,c,x,delta) = min(dfs(pos,c,x+(delta ? 1 : -1),delta)+l-pos,min(dfs(pos+1,c*10+str[pos+1]-x,x,1),dfs(pos+1,c*10+str[pos+1]-x,x,0))) ;
	return f(pos,c,x,delta) ; 
}
int main(){
	//freopen("in.txt","r",stdin) ;
	str[1] = 0 ; scanf("%s",str+2) ;
	l = strlen(str+2)+1 ;
	for(int i = 2 ; i <= l ; i++) str[i] = str[i]-'0' ;
	X = 5*l ; C = X/10+1 ; memset(f,-1,sizeof f) ; 
	printf("%d\n",dfs(0,0,0,1)) ; 
	return 0 ;  
}