#include <iostream>

using namespace std;
int granica(long long V){
    int br=1;
    while(10*br<=V)
        br*=10;
    if(5*br<=V)
        return br*5;
    else if(2*br<=V)
        return 2*br;
    return br;
}

int brojNovcanica(long long V){
    if(V==1 || V==2 || V==5)
        return 1;
    else
        return brojNovcanica(V-granica(V))+1;
}
int main()
{

    long long V;
    cin>>V;
    long long dp[V];
    dp[0]=1;
    dp[1]=1;
    dp[4]=1;
    for(int i=4;i<V;++i)
        dp[i]=dp[i-granica(i)]+1;
    cout << dp[V-1] << endl;
    return 0;
}