#include <bits/stdc++.h>
using namespace std;
int len = 0;
void To_Array(int n, int num[]) {
  int cnt = 0;
  while (n > 0) {
    num[cnt] = n % 10;
    n /= 10;
    cnt++;
  }
  len = cnt;
}
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);
  To_Array(T, num);
  for (int i = 356; i < T && T > 356; i++) {
    To_Array(i, num);
    for (int j = 0; j < len; j++) {
      if (num[j] != 3 && num[j] != 5 && num[j] != 7) break;
      table[num[j]]++;
    }
    if (table[3] > 0 && table[5] > 0 && table[7] > 0 &&
        (table[3] + table[5] + table[7] == len)) {
      value++;
    }
    memset(table, 0, sizeof(table));
  }
  printf("%d", value);
  return 0;
}
