#include <bits/stdc++.h>

using namespace std;

int decimaltoOctal(int deciNum)
{
 
    int octalNum = 0, countval = 1;
    int dNo = deciNum;
 
    while (deciNum != 0) {
 
        int remainder = deciNum % 8;
 
        octalNum += remainder * countval;
 
        countval = countval * 10;
        deciNum /= 8;
    }
    
    return octalNum;
}

int main() {

	int n;
	cin>>n;

	set<int> s;

	for(int i=1; i<=n; i++) {

		string deci = to_string(i);
		string oct = to_string(decimaltoOctal(i));

		for(int j=0; j<deci.length(); j++) {

			if(deci[j] == '7') s.insert(i);
		}

		for(int j=0; j<oct.length(); j++) {

			if(oct[j] == '7') s.insert(i);
		}
	}

	cout<<n-s.size()<<endl;

	return 0;
}
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define be(x) x.begin(), x.end()
using namespace std;

int main()
{

    string s;
    cin  >> s;

    for (int i = 1; i < s.size(); i++)
    {
        cout<<s[i];
    }
    cout<<s[0]<<endl;
    

    return 0;
}
