#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> ans_vec;
void check(int x) {
  int keep = x;
  int three = 0, five = 0, seven = 0;
  while (x > 0) {
    int r = x % 10;
    if (r == 3) {
      three++;
      x /= 10;
    } else if (r == 5) {
      five++;
      x /= 10;
    } else if (r == 7) {
      seven++;
      x /= 10;
    } else if (r != 3 && r != 5 && r != 7) {
      exit(0);
    }
  }
  if (three != 0 && five != 0 && seven != 0 && keep < N) {
    ans_vec.push_back(keep);
  }
}
void dfs(int x) {
  check(x);
  if (x < N) {
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
  }
}
int main() {
  cin >> N;
  dfs(0);
  cout << ans_vec.size() << endl;
  return 0;
}
