#include<bits/stdc++.h>
#include<iterator>
#include<math.h>

#define optimize()      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll                     long long int
#define pb                   push_back
#define fi(a,b,c)           for(i=a;i<=b;i=i+c)
#define fia(a,b,c)         for(i=a;i<b;i=i+c)
#define scl(n)              scanf("%lld", &n)
#define scf(n)              scanf("%lf", &n)
#define pfl(x)              printf("%lld\n",x)
#define ct                    cout
#define cn                   cin
#define nl                    '\n'
using namespace std;
int oct(int n)
{
    while(n!=0)
    {
        int x=n%8;
        if(x==7) return 1;
        n/=8;
    }
    return 0;
}
int dec(int n)
{
    while(n!=0)
    {
        int x=n%10;
        if(x==7) return 1;
        n/=10;
    }
    return 0;
}


// Driver program to test above
int main()
{
    int n,i,c=0;
    cn>>n;
    fi(1,n,1)
    {
        if(dec(i)) {c++;continue;}
        if(oct(i)) c++;
    }
    ct<<n-c<<nl;


}



























   #include<bits/stdc++.h>
   #include<iostream>

   typedef long long ll;

   using namespace std;

   int main(){
         
         int n,m;
         cin>>n;
         ll sum=0;
         while(n-->0){
            ll a,b;
            cin>>a>>b;

            sum += ((a+b)*(b-a+1))/2;
         }
         cout<<sum<<endl;
      return 0;
   }

