#include <bits/stdc++.h>
using namespace std;
bool check(int n) {
  bool e = 0, f = 0, g = 0;
  while (n > 0) {
    if (n % 10 == 7)
      e = 1;
    else if (n % 10 == 5)
      f = 1;
    else if (n % 10 == 3)
      g = 1;
    n /= 10;
  }
  if (e && f && g)
    return 1;
  else
    return 0;
}
int main() {
  int n, m = 1, ans = 0;
  cin >> n;
  queue<int> q;
  q.push(3);
  q.push(5);
  q.push(7);
  while (m <= n) {
    m = q.front();
    q.pop();
    q.push(m * 10 + 3);
    q.push(m * 10 + 5);
    q.push(m * 10 + 7);
    if (check(m)) ans++;
  }
  cout << ans << endl;
}
