#include <bits/stdc++.h>

using namespace std;

int main()
{
   long long n,k=1,s=0;
   scanf("%llu",&n);
   vector<long long>a;
   int i=0;
   a.push_back(1);
   a.push_back(2);
   a.push_back(5);
   i=2;
   while(a[i]<=n)
   {
       a.push_back(1*pow(10,k));
       a.push_back(2*pow(10,k));
       a.push_back(5*pow(10,k));
       i=i+2;
       k++;

   }
   long long  z=0;
   for( int k=i; k>=0; k--)
   {
       if(z<n)
       {
           z+=a[k];
           s++;
           k++;
       }
       else
       {
       if(z>n)
       {
           z-=a[k];
           s--;
       }
       else
       {
       if(z==n)
       {
           cout<<s;
           break;
       }
       }}

   }
}