#include <bits/stdc++.h>
using namespace std;
int n;
int dfs(long long a) {
  if (n < a) return 0;
  int f3, f5, f7;
  f3 = f5 = f7 = 0;
  long long t = a;
  while (t) {
    int b = t % 10;
    if (t == 3)
      f3 = 1;
    else if (t == 5)
      f5 = 1;
    else if (t == 7)
      f7 = 1;
    t /= 10;
  }
  int f = f3 && f5 && f7;
  return f + dfs(a * 10 + 3) + dfs(a * 10 + 5) * dfs(a * 10 + 7);
}
int main() {
  cin >> n;
  cout << dfs(0) << endl;
  return 0;
}
