#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const long long MOD = 1000000007LL;
class Radix {
 private:
  const char* s;
  int a[100000];

 public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for (i = 0; s[i]; ++i) a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if (!p) return "a";
    char t[64000] = {};
    for (i = 62000; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) { return to(to(t, p), q); }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]];
    return sm;
  }
};
int main() {
  int n;
  std::cin >> n;
  int c = 0;
  for (int i = 1;; i++) {
    Radix r;
    string dum = r.to(i, 3);
    if (stoi(dum) > n) {
      std::cout << c << std::endl;
      exit(0);
    }
    int rin = stoi(dum);
    string dumdum = dum;
    for (int j = dum.size();; j++) {
      if (j != dumdum.size()) dum.insert(dum.begin(), '0');
      std::vector<int> han(3, 0);
      bool h = 1;
      for (int k = 0; k < (int)(dum.size()); k++) {
        if (dum[k] == '0' || dum[k] == '3') {
          han[0]++;
          dum[k] = '3';
        }
        if (dum[k] == '1' || dum[k] == '5') {
          han[1]++;
          dum[k] = '5';
        }
        if (dum[k] == '2' || dum[k] == '7') {
          han[2]++;
          dum[k] = '7';
        }
      }
      if (stoi(dum) > n) {
        break;
      }
      for (int k = 0; k < (int)(3); k++)
        if (han[k] == 0) h = 0;
      if (h) c++;
    }
  }
}
