#include <bits/stdc++.h>
bool judge(int i) {
  int a[3] = {0}, t;
  while (i) {
    t = i % 10;
    if (t == 3)
      a[0] = 1;
    else if (t == 5)
      a[1] = 1;
    else if (t == 7)
      a[2] = 1;
    else
      return false;
    i /= 10;
  }
  for (int j = 0; j < 3; j++) {
    if (a[j] == 0) return false;
  }
  return true;
}
int main() {
  int T;
  while (scanf("%d", &T) != EOF) {
    int ans = 0;
    for (int i = 3; i <= T; i += 10) {
      if (judge(i)) {
        ans++;
      }
      if (judge(i + 2)) {
        ans++;
      }
      if (judge(i + 4)) {
        ans++;
      }
    }
    printf("%d\n", ans);
  }
}
