#include <bits/stdc++.h>
using namespace std;
int len = 0;
int To_Array(int n, int num[]) {
  int cnt = 0;
  int table[10];
  memset(table, 0, sizeof(table));
  while (n > 0) {
    if (n % 10 != 3 && n % 10 != 5 && n % 10 != 7) return 0;
    num[cnt] = n % 10;
    table[num[cnt]]++;
    n /= 10;
    cnt++;
  }
  if (table[3] > 0 && table[5] > 0 && table[7] > 0 &&
      (table[3] + table[5] + table[7] == cnt)) {
    return 1;
  }
  return 0;
}
int main(int argc, char* argv[]) {
  int T;
  int num[12];
  int table[10];
  int value = 0;
  memset(table, 0, sizeof(table));
  scanf("%d", &T);
  for (int i = 356; i <= T && T > 356; i++) {
    if (To_Array(i, num)) value++;
  }
  printf("%d", value);
  return 0;
}
