#include <bits/stdc++.h>
using namespace std;
int n;
struct Node {
  int v;
  int layer;
};
vector<Node> Adj[1010];
bool inq[1010] = {false};
int l;
int ans = 0;
void BFS(int s) {
  queue<Node> q;
  Node start;
  start.v = s;
  start.layer = 0;
  q.push(start);
  inq[start.v] = true;
  while (!q.empty()) {
    Node topNode = q.front();
    q.pop();
    int u = topNode.v;
    for (int i = 0; i < Adj[u].size(); i++) {
      Node next = Adj[u][i];
      next.layer = topNode.layer + 1;
      if (inq[next.v] == false && next.layer <= l) {
        q.push(next);
        ans++;
        inq[next.v] = true;
      }
    }
  }
}
void BFSTrave() {
  for (int u = 0; u < n; u++) {
    if (inq[u] == false) {
      BFS(u);
    }
  }
}
int main() {
  int a;
  cin >> a;
  stringstream s;
  int count = 0;
  for (int i = 357; i <= a; i++) {
    string temp;
    s << i;
    s >> temp;
    s.clear();
    if (temp.find('3') != string::npos && temp.find('5') != string::npos &&
        temp.find('7') != string::npos && temp.find('0') == string::npos &&
        temp.find('1') == string::npos && temp.find('2') == string::npos &&
        temp.find('4') == string::npos && temp.find('6') == string::npos &&
        temp.find('8') == string::npos && temp.find('9') == string::npos) {
      count++;
    }
  }
  printf("%d", count);
  return 0;
}
