#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){
    long long dp[V];
    dp[0]=1;
    dp[1]=1;
    dp[4]=1;
    for(int i=5;i<V;++i)
        dp[i]=dp[i-granica(i)]+1;
    return dp[V-1];

}
int main()
{

    long long V;
    cin>>V;
    cout << brojNovcanica(V) << endl;
    return 0;
}