#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void comb(vector<vector<long long>> &v) {
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
}
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
int check(string i) {
  int num = stoi(i);
  int check7 = 0;
  int check5 = 0;
  int check3 = 0;
  while (num != 0) {
    if (num % 10 == 7) check7 = 1;
    if (num % 10 == 5) check5 = 1;
    if (num % 10 == 3) check3 = 1;
    num /= 10;
  }
  if (check7 * check5 * check3 == 1) return 1;
  return 0;
}
int search(string i, int N) {
  int cnt = 0;
  if (stol(i) >= N) return 0;
  if (check(i)) cnt++;
  cnt += search(i + "7", N);
  cnt += search(i + "5", N);
  cnt += search(i + "3", N);
  return cnt;
}
int main() {
  int N;
  cin >> N;
  cout << search("3", N) + search("5", N) + search("7", N) << endl;
  return 0;
}
