#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <set>
#include <bitset>
#include <iterator>

#define len(v) v.size()
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define pb push_back
#define endl '\n'

using namespace std;

string toOctal(int n) {
	string ans = "";
	while(n != 0) {
		ans += to_string(n % 8);
		n /= 8;
	}
	return ans;
}

bool isLucky(int n) {
	string s = to_string(n);
	for(auto ch: s)
		if(ch == '7')
			return false;
	s = toOctal(n);
	for(auto ch: s)
		if(ch == '7')
			return false;
	return true;
}

int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int N; cin >> N;
	int ans = 0;
	for(int i = 1;i <= N;++i)
		ans += isLucky(i);

	cout << ans << endl;
    
	return 0;
}

#include <bits/stdc++.h>
#include <string.h>
#include <math.h>
using namespace std;

#define loop(i, x, y) for (i = x; i < y; i++)
#define loopr(i, x, y) for (i = x; i > y; i--)

//use *it instead of it
#define vloop(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define vloopr(it, x) for (auto it = x.end() - 1; it != x.begin() - 1; it--)

#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair

#define debug(x) cerr << #x << ":" << x << endl
#define yo cerr << "yo" << endl

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

#define test(t) \
    ll t;       \
    cin >> t;   \
    while (t--)

//use double
#define precision(x)       \
    cout.setf(ios::fixed); \
    cout << setprecision(10) << x << endl;

// ll gcd(ll x_f, ll y_f)
// {
//     if (x_f == 0)
//         return y_f;
//     return gcd(y_f % x_f, x_f);
// }

// ll power(ll x_f, ll y_f, ll m_f)
// {
//     ll res_f = 1;

//     x_f = x_f% m_f;
//     while (y_f)
//     {
//         if (y_f & 1)
//             res_f = (res_f * x_f) % m_f;
//         y_f = y_f >> 1;
//         x_f = (x_f * x_f) % m_f;
//     }
//     return res_f;
// }

// ll less(ll x_f, ll y_f)
// {
//     return (x_f > y_f) ? y_f : x_f;
// }
// ll more(ll x_f, ll y_f)
// {
//     return (x_f < y_f) ? y_f : x_f;
// }

ll fac(ll x_f)
{
    ll fac_f = 1;
    for (ll i = 1; i <= x_f; i++)
    {
        fac_f *= i;
        fac_f = fac_f % MOD;
    }
    return fac_f;
}

bool composite[1000007] = {false};
void seive(ll x)
{
    composite[0] = true;
    composite[1] = true;
    for (ll i = 2; i <= x; i++)
    {
        if (!composite[i])
        {
            for (ll j = 2 * i; j <= x; j += i)
            {
                composite[j] = true;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n, ans = 0;
    cin >> n;

    for (ll i = 1; i <= n; i++)
    {
        ll num1 = i, num2 = i, flag = 0;
        //    debug(num);
        while (num1 > 0 && num2 > 0)
        {
            if (num1 % 10 == 7 || num2 % 8 == 7)
            {
                flag = 1;
                break;
            }
            num1 = num1 / 10;
            num2 = num2 / 8;
        }
        if (flag == 1)
            continue;
        //cout << i << endl;
        ans++;
    }
    cout << ans << endl;
    return 0;
}