#include <iostream>
#include <vector>
using namespace std;
int N;

long long dfs(long long x, int bit, long long t){
  if(x > N) return 0;
  long long ret = (bit==7);
  ret += dfs(t*3+x, (bit|1), t*10);
  ret += dfs(t*5+x, (bit|2), t*10);
  ret += dfs(t*7+x, (bit|4), t*10);
  return ret;
}

int main(){
  cin >> N;
  cout << dfs(0,0,1) << endl;
  return 0;
}
