#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
long long mypow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return ans;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ifstream in("");
  ofstream out("");
  clock_t begin = clock();
  int n;
  cin >> n;
  string s = to_string(n);
  map<string, bool> mymp;
  queue<string> Q;
  Q.push("3");
  Q.push("5");
  Q.push("7");
  int res = 0;
  while (!Q.empty()) {
    string tmp = Q.front();
    Q.pop();
    if (mymp.find(tmp) != mymp.end()) continue;
    mymp[tmp] = 1;
    if (stoi(tmp) < n && (int)tmp.size() >= 3 &&
        tmp.find("3") != string::npos && tmp.find("5") != string::npos &&
        tmp.find("7") != string::npos) {
      res++;
    }
    if ((int)tmp.size() == (int)s.size()) continue;
    Q.push(tmp + "7");
    Q.push(tmp + "5");
    Q.push(tmp + "3");
  }
  cout << res << '\n';
  clock_t end = clock();
  double esecs = double(end - begin) / CLOCKS_PER_SEC;
  return 0;
}
