#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;

void MAIN() {
    scanf("%d", &N);
    int ans =0 ;
    for (int i=1; i<=N; i++) {
	bool ok = true;
	{
	    int m = i;
	    while (m) {
		if (m % 10 == 7) {
		    ok = false;
		    break;
		}
		m /= 10;
	    }
	}
	if (ok) {
	    int m = i;
	    while (m) {
		if (m % 8 == 7) {
		    ok = false;
		    break;
		}
		m /= 8;
	    }
	}

	if (ok) ans++;
    }

    printf("%d\n", ans);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,arr[1006];
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int x=0,c,max_c=0,flag=0;
    for(int i=2;i<=1000;i++)
    {
        c=0;
        for(int j=0;j<n;j++)
        {
            if(arr[j]%i==0)
            {
                c++;
            }
        }
        if(c>max_c)
        {
            max_c=c;
            x=i;
            flag=1;
        }
    }
    if(flag==1)
    {
        cout<<x<<endl;
    }
    else
    {
        cout<<"0"<<endl;
    }
    return 0;
}
