#include<bits/stdc++.h>
using namespace std;
const int inf=1000000;
int n,a[10000],lim1,lim2,f[60][100][1000][3];
char s[10000];
int dp(int p,int x,int y,int z)
{
	if(p==n) return x?inf:0;
	if(abs(x)>lim2||abs(y)>lim1) return inf;
	if(f[p][x][y][z]>=0) return f[p][x][y][z];
	return f[p][x][y][z]=min(dp(p,x,y+(z<<1)-1,z)+n-p,min(dp(p+1,x*10+a[p+1]-y,y,0),dp(p+1,x*10+a[p+1]-y,y,1)));
}
int main()
{
	scanf("%s",s+2);
	n=strlen(s+2)+1;
	for(int i=2;i<=n;i++) a[i]=s[i]-48;
	lim1=n+(n<<2);
	lim2=lim1/10+1;
	memset(f,-1,sizeof(f));
	printf("%d",dp(0,0,0,1));
}