#include <bits/stdc++.h>
using namespace std;
bool check(int x) {
  bool lack3 = true, lack5 = true, lack7 = true;
  while (x > 0) {
    if (x % 10 == 3) lack3 = false;
    if (x % 10 == 5) lack5 = false;
    if (x % 10 == 7) lack7 = false;
    x /= 10;
  }
  if (lack3 || lack5 || lack7)
    return true;
  else
    return false;
}
int count(int x, int n) {
  int c = 0;
  if (x > n) return 0;
  c += count(10 * x + 3, n) + count(10 * x + 5, n) + count(10 * x + 7, n);
  if (check(x))
    return c;
  else
    return c + 1;
}
int main() {
  int n;
  cin >> n;
  cout << count(0, n);
}
