#include <bits/stdc++.h>
using namespace std;
long long gi() {
  char cc = getchar();
  long long cn = 0, flus = 1;
  while (cc < '0' || cc > '9') {
    if (cc == '-') flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
  return cn * flus;
}
const long long N = 1e6 + 5;
char s[N];
long long f[N][2];
signed main() {
  scanf("%s", s + 1);
  long long n = strlen(s + 1), Ans = 0;
  s[0] = '0';
  f[n + 1][0] = 0, f[n + 1][1] = 100;
  for (register long long i = n; i >= 0; --i) {
    long long u = s[i] - '0';
    f[i][1] = min(f[i + 1][1] - u - 1, f[i + 1][0] - u) + 10;
    f[i][0] = min(f[i + 1][1] + u + 1, f[i + 1][0] + u);
  }
  cout << f[0][0] << endl;
  return 0;
}
