#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x, y) make_pair(x, y)
#define mem(dp, a) memset(dp, a, sizeof dp);
#define all(a) a.begin(), a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll, ll> pp;

#define debug(x) cout << #x << " :: " << x << "\n";
#define debug2(x, y) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\n";
#define debug3(x, y, z) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pp, null_type, less<pp>, rb_tree_tag, tree_order_statistics_node_update>

ll power(ll b, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2)
        {
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost;
    ll n;
    cin >> n;
    ll num=1;
    for (ll i = 2; i <= n; i++)
    {
        num = (num * i) / __gcd(i, num);
    }
    cout << num + 1;
    return 0;
}

//#pragma GCC optimize(2) 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstring>
#include<vector> 
#include<algorithm>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
//#define int long long
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=998244353;
const double eps=1e-3;
int t,n,m,a[110][110],ans;
string s; 
bool check(int x)
{
	int k=x,p=x;
	while(k)
	{
		if(k%10==7) return 0;
		k/=10;
	}
	while(p)
	{
		if(p%8==7) return 0;
		p/=8;
	}
	return 1;
}
int main()
{
//  ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		if(check(i)) ans++;
	cout<<ans<<endl;
    return 0;
}
