#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f, eps = 0.001;
void printar(int arr[], int n) {
  for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}
int s(int n) {
  int x;
  int x1 = 0, x2 = 0, x3 = 0;
  int y = n;
  while (n) {
    x = n % 10;
    n /= 10;
    if (!(x == 3 || x == 5 || x == 7)) {
      return 0;
    }
    if (x == 3) x1++;
    if (x == 5) x2++;
    if (x == 7) x3++;
  }
  if (x1 && x2 && x3) {
    return 1;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ;
  int n, cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (s(i)) cnt++;
  }
  cout << cnt;
  return 0;
}
