#include<iostream>
#include<string>
#include<complex>
using namespace std;

int n;
int ans = 0;

int recurse(string now){
  int kaisu;
  if(stoi(now) > n){
    return 0;
  }
  
  kaisu = recurse(3 + now) + recurse(5 + now) + recurse(7 + now);
  
  return kaisu + 1;
}

int main(){
  
  cin >> n;
  cout << recurse(n) << endl;
  return 0;
}