#include <bits/stdc++.h>
using namespace std;
queue<int> q;
void shigosan(int N, int m) {
  if (N <= m) return;
  q.push(m * 10 + 3);
  q.push(m * 10 + 5);
  q.push(m * 10 + 7);
  shigosan(N, m * 10 + 3);
  shigosan(N, m * 10 + 5);
  shigosan(N, m * 10 + 7);
}
bool check_shit(int a) {
  int flag_3 = 0, flag_5 = 0, flag_7 = 0;
  while (a) {
    if (a % 10 == 3)
      flag_3 = 1;
    else if (a % 10 == 5)
      flag_5 = 1;
    else if (a % 10 == 7)
      flag_7 = 1;
    a /= 10;
  }
  if (flag_3 && flag_5 && flag_7)
    return true;
  else
    return false;
}
int main() {
  int N;
  cin >> N;
  shigosan(N, 0);
  int ans = 0;
  while (!q.empty()) {
    if (check_shit(q.front()) && N >= q.front()) ans++;
    q.pop();
  }
  cout << ans << endl;
}
