#include <bits/stdc++.h>
using namespace std;
int c = 0;
int n;
string itos(int value) {
  char buffer[20];
  sprintf(buffer, "%d", value);
  return string(buffer);
}
int dfs(int k) {
  if (k > n) return 0;
  string s = itos(k);
  int is753 = 0;
  bool has3 = false, has5 = false, has7 = false;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '3') {
      has3 = true;
    }
    if (s[i] == '5') {
      has5 = true;
    }
    if (s[i] == '7') {
      has7 = true;
    }
  }
  if (has3 && has5 && has7) {
    is753 = 1;
  }
  return dfs(k * 10 + 3) + dfs(k * 10 + 5) + dfs(k * 10 + 7) + is753;
}
int main() {
  cin >> n;
  cout << dfs(0) << endl;
}
