#include <bits/stdc++.h>
using namespace std;
int check(int n) {
  int c3 = 0;
  int c5 = 0;
  int c7 = 0;
  while (n) {
    if (n % 10 == 3)
      c3 = 1;
    else if (n % 10 == 5)
      c5 = 1;
    else
      c7 = 1;
    n /= 10;
  }
  if (c3 && c5 && c7) return 1;
  return 0;
}
int dfs(int n, int lim) {
  int i = 0;
  if (n <= lim) {
    i = check(n);
    i += dfs(10 * n + 3, lim);
    i += dfs(10 * n + 5, lim);
    i += dfs(10 * n + 7, lim);
  }
  return i;
}
int main() {
  int n;
  cin >> n;
  cout << dfs(0, n) << endl;
  return 0;
}
