#include <iostream>
#include <cmath>
using namespace std;

int brcifara(long long n) 
{ 
    int br = 0; 
    while (n != 0) { 
        n = n / 10; 
        ++br; 
    } 
    return br; 
} 

int main(int argc, char** argv) {
	long long v;
	long long a;
	int bd=2,r=0,k,pk;
	cin>>v;
	int d [3];
	d[0]=1;
	d[1]=2;
	d[2]=5;
	pk=brcifara(v)-1;
	while(v>0){
		if(bd==-1) bd=2;
		k=(brcifara(v))-1;
		if(k!=pk){
			pk--;
			bd=2;
		}
		a=d[bd]*pow(10,k);
			if(v-a>=0){	
				v=v-a;
				r=r+1;
			}
			else bd=bd-1;
			
	}
	cout<<r;
	return 0;
}