#include<stdio.h>
#include<bits/stdc++.h>
#define R register
const int maxbuf=1<<20;
char buf[maxbuf],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,maxbuf,stdin),p1==p2)?0:*p1++)
inline void read(int &x) {
	x=0;
	int flag=0;
	char t=GC;
	while(t<'0'||t>'9') {
		if(t=='-') {
			flag=1;
		}
		t=GC;
	}
	while(t>='0'&&t<='9') {
		x=x*10+t-48,t=GC;
	}
	x=flag?-x:x;
	return ;
}
inline void readll(long long &x) {
	x=0;
	int flag=0;
	char t=GC;
	while(t<'0'||t>'9') {
		if(t=='-') {
			flag=1;
		}
		t=GC;
	}
	while(t>='0'&&t<='9') {
		x=x*10+t-48,t=GC;
	}
	x=flag?-x:x;
	return ;
}
const int maxn=55,maxm=405;
const int inf=200,INF=0x3f3f3f3f;
int n;
char str[maxn];
int f[2][maxn][maxm][maxm];
inline bool inborder(int x,int y) {
	return x>=-inf&&x<=inf&&y>=-inf&&y<=inf;
}
inline void dfs(int dir,int pos,int lazy,int rem) {
	int &F=f[dir<0][pos][lazy+200][rem+200];
	if(F>=0) {
		return ;
	}
	if(pos==n) {
		F=rem?INF:0;
		return ;
	}
	F=INF;
	const int cur=str[pos]-lazy+rem*10;
	if(inborder(lazy,cur)) {
		dfs(1,pos+1,lazy,cur);
		dfs(-1,pos+1,lazy,cur);
		F=std::min(f[0][pos+1][lazy+200][cur+200],f[1][pos+1][lazy+200][cur+200]);
	}
	if(inborder(lazy+dir,rem)) {
		dfs(dir,pos,lazy+dir,rem);
		F=std::min(F,f[dir<0][pos][lazy+dir+200][rem+200]+n-pos);
	}
	return ;
}
int main(void) {
	scanf("%s",str+1);
	str[0]=48;
	n=strlen(str);
//	printf("%d %d\n",0,(int)str[0]);
	for(R int i=0; i<n; ++i) {
		str[i]^=48;
//		printf("%d %d\n",i,(int)str[i]);
	}
	memset(f,-1,sizeof(f));
	dfs(1,0,0,0);
	printf("%d",f[0][0][200][200]);
	return 0;
}
