#include <bits/stdc++.h>
using namespace std;
int a[3] = {3, 5, 7};
int res = 0;
void dfs(int x, int y, int limit);
bool judge(int n);
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      dfs(a[i], a[j], N);
    }
  }
  cout << res << endl;
}
void dfs(int x, int y, int limit) {
  if (x > limit) return;
  int m = 10 * x + y;
  if (m > limit) return;
  if (judge(m)) {
    res++;
  }
  for (int i = 0; i < 3; i++) {
    dfs(m, a[i], limit);
  }
  return;
}
bool judge(int n) {
  bool three_flag = false;
  bool five_flag = false;
  bool seven_flag = false;
  while (n > 0) {
    int m = n % 10;
    n /= 10;
    if (m == 3) {
      three_flag = true;
    } else if (m == 5) {
      five_flag = true;
    } else if (m == 7) {
      seven_flag = true;
    } else {
      return false;
    }
  }
  if (three_flag && five_flag && seven_flag) {
    return true;
  }
  return false;
}
