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

int main() {
  int n;
  cin >> n;
  int x, cnt = 0;
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    flag = false;
    x = i;
    while (x) {
      if (x % 10 == 7) {
        flag = true;
        break;
      } else {
        x /= 10;
      }
    }
    if (flag) continue;
    x = i;
    while (x) {
      if (x % 8 == 7) {
        flag = true;
        break;
      } else {
        x /= 8;
      }
    }
    if (flag) continue;
    cnt++;
  }
  cout << cnt << endl;
}
#include <iostream>
using namespace std;

int h8(int x){
    int x0,x1,x2,x3,x4,x5;
    x5=x/32768;
    x4=(x-x5*32768)/4096;
    x3=(x-x5*32768-x4*4096)/512;
    x2=(x-x5*32768-x4*4096-x3*512)/64;
    x1=(x-x5*32768-x4*4096-x3*512-x2*64)/8;
    x0=x-x5*32768-x4*4096-x3*512-x2*64-x1*8;
    return x0+x1*10+x2*100+x3*1000+x4*10000+x5*100000;
}

bool h(int x){
    string str=to_string(x);
    for(int i=0;i<str.length();i++){
        if(str[i]=='7') return true;
    }
    return false;
}

int main(){
    int n,cnt=0; cin>>n;
    for(int i=1;i<=n;i++){
        if(h(i)==false&&h(h8(i))==false) cnt++;
    }
    cout<<cnt<<endl;  
    return 0;
}