#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    stringstream ss10;
    ss10 << dec << i;
    string s10 = ss10.str();
    stringstream ss8;
    ss8 << oct << i;
    string s8 = ss8.str();
    if (s10.find("7") != string::npos) {
      cnt++;
    } else if (s8.find("7") != string::npos) {
      cnt++;
    }
  }

  printf("%d\n", n - cnt);
  return 0;
}
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<stdio.h>
#include<math.h>
#include<string>
#include<new>
#include<iterator>
using namespace std;
int main()
 
{int n;
 cin>>n;
 if(n==1){
 	cout<<"0"<<endl;
 }
 else{
 	int k=n-2;
 	cout<<k+1<<endl;
 }
 
}
