#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int lenHelper(unsigned long long x) {
    if (x >= 100000000000000000) return 18;
    if (x >= 10000000000000000)  return 17;
    if (x >= 1000000000000000)   return 16;
    if (x >= 100000000000000)    return 15;
    if (x >= 10000000000000)     return 14;
    if (x >= 1000000000000)      return 13;
    if (x >= 100000000000)       return 12;
    if (x >= 10000000000)        return 11;
    if (x >= 1000000000)         return 10;
    if (x >= 100000000)          return 9;
    if (x >= 10000000)           return 8;
    if (x >= 1000000)            return 7;
    if (x >= 100000)             return 6;
    if (x >= 10000)              return 5;
    if (x >= 1000)               return 4;
    if (x >= 100)                return 3;
    if (x >= 10)                 return 2;
    return 1;
}

short int printLen(long long int x) {
    return x < 0 ? lenHelper(-x) + 1 : lenHelper(x);
}

int add(int x){
    if (x == 1 || x == 2 || x == 5)           return 1;
    if (x == 3 || x == 4 || x == 6 || x == 7) return 2;
    if (x == 8 || x == 9)                     return 3;
    if (x == 0)                               return 0;
}

int main(){
    long long int v;
    short int sum = 0;

    scanf("%lli", &v);
    short int length = printLen(v);

    for(int i = length; i >= 1; i--){
        int temp = v / pow(10, i - 1);
        sum += add(temp);
        v -= temp * pow(10, i - 1);
    }

    printf("%hi", sum);

    return 0;
}