#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int mx = 100005;
const long long infL = 0xf3f3f3f3f3f3f3f;
const double eps = 1e-9;
const double pi = acos(-1.0);
queue<int> q;
set<int> st;
int main() {
  int n, cnt = 0;
  scanf("%d", &n);
  q.push(3);
  q.push(5);
  q.push(7);
  while (q.front() < n) {
    int p = q.front();
    q.pop();
    if (st.find(p) == st.end()) {
      st.insert(p);
      int x = p, d3 = 0, d5 = 0, d7 = 0;
      while (x) {
        int l = x % 10;
        d3 += (l == 3);
        d5 += (l == 5);
        d7 += (l == 7);
        x /= 10;
      }
      if (d3 && d5 && d7) cnt++;
      q.push(p * 10 + 3);
      q.push(p * 10 + 5);
      q.push(p * 10 + 7);
    }
  }
  printf("%d", (int)cnt), printf("\n");
  return 0;
}
