#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 123;
const int mod = 998244353;



int n, m;
int a[N];

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		a[i] = a[i - 1];
		int j = i;
		bool ok = 1;
		while(j > 1) {
			ok &= ((j % 10) != 7);
			j /= 10;
		}

		j = i;
		while(j) {
			ok &= ((j % 8) != 7);
			j /= 8;
		}
		if(ok)
			a[i]++;

	}
	cout << a[n];
	return 0;
}
//N?
























#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb3(x, y, z) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define deb4(x, y, z, w) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << " | " << #w << ": " << w << endl
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define vvi vector<vector<int>>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int curr = i;
        bool valid = true;
        while (curr)
        {
            if (curr % 10 == 7)
            {
                valid = false;
                break;
            }
            else
            {
                curr = curr / 10;
            }
        }
        if (!valid)
            continue;
        curr = i;
        while (curr)
        {
            if (curr % 8 == 7)
            {
                valid = false;
                break;
            }
            else
            {
                curr = curr / 8;
            }
        }
        if (valid)
            ans++;
    }
    cout << ans << endl;
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/