#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int n_digit(int k, int n) {
  int res = 0;
  int d = 1;
  while (k != 0) {
    res += d * (k % n);
    k /= n;
    d *= 10;
  }
  return res;
}
int sitigosan(int k, int d) {
  string tmp = to_string(k);
  while (tmp.size() < d) {
    tmp = '0' + tmp;
  }
  string res = "";
  for (int i = (0); i < (tmp.size()); ++i) {
    if (tmp[i] == '0')
      res += '3';
    else if (tmp[i] == '1')
      res += '5';
    else
      res += '7';
  }
  return stoi(res);
}
bool check(int k, int d) {
  int cnt[3];
  for (int i = (0); i < (3); ++i) cnt[i] = 0;
  for (int i = (0); i < (d); ++i) {
    cnt[((k % 10) % 3)]++;
    k /= 10;
  }
  for (int i = (0); i < (3); ++i) {
    if (cnt[i] == 0) return false;
  }
  return true;
}
int main() {
  int N;
  cin >> N;
  int d = 1;
  int N_tmp = N;
  for (int i = (0); i < (N); ++i) {
    if (N_tmp /= 10) d += 1;
  }
  int m = 1;
  for (int i = (0); i < (d); ++i) m *= 3;
  int ans = 0;
  for (int j = (0); j < (d + 1); ++j) {
    for (int i = (0); i < (m); ++i) {
      int sansinsuu = n_digit(i, 3);
      if (check(sansinsuu, j) && N >= sitigosan(sansinsuu, j)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
