#include <bits/stdc++.h>
using namespace std;
int three(long long int &n, vector<long long int> &cnt);
int change(long long int n);
int three(long long int &n, vector<long long int> &cnt) {
  long long int n_;
  long long int tmp;
  for (int i = 0; i < 10; i++) {
    n_ = n;
    n_ /= pow(10, i);
    tmp = change(n_ % 10);
    if (tmp == 3) {
      n -= 4 * pow(10, i);
      cnt[2]--;
      cnt[0]++;
    } else if (tmp == 1) {
      n += 3 * pow(10, i);
      cnt[0]++;
      break;
    } else if (tmp == 5) {
      n += 2 * pow(10, i);
      cnt[0]--;
      cnt[1]++;
      break;
    } else if (tmp == 7) {
      n += 2 * pow(10, i);
      cnt[1]--;
      cnt[2]++;
      break;
    }
  }
  return 0;
}
int change(long long int n) {
  if (n == 3) {
    return 5;
  }
  if (n == 5) {
    return 7;
  }
  if (n == 7) {
    return 3;
  }
  if (n == 0) {
    return 1;
  }
}
int main() {
  long long int n;
  cin >> n;
  vector<long long int> cnt(3, 1);
  long long int tmp;
  long long int n_ = n;
  n = n_;
  n_ = 357;
  if (n < 357) {
    cout << 0 << endl;
    return 0;
  }
  long long int ans = 1;
  while (n_ <= n) {
    three(n_, cnt);
    if (cnt[0] != 0 && cnt[1] != 0 && cnt[2] != 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
