#include <bits/stdc++.h>
using namespace std;
bool divide(int n) {
  int cnt_other = 0, cnt3 = 0, cnt5 = 0, cnt7 = 0;
  while (n > 0) {
    int tmp = n % 10;
    switch (tmp) {
      case 3:
        cnt3++;
        break;
      case 5:
        cnt5++;
        break;
      case 7:
        cnt7++;
        break;
      default:
        cnt_other++;
        break;
    }
    n /= 10;
  }
  if (cnt_other == 0 && cnt3 > 0 && cnt5 > 0 && cnt7 > 0) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (divide(i)) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
