function Main(input) {
  input = input.split("\n");
  var N = input[0].split("").map(i=>parseInt(i));
  var ans =0;
  for(var i=N.length-1;i>=0;i--){
    if(N[i]<=5){
      ans+=N[i];
    }else{
      ans+=(10-N[i]+1)
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));