#include <bits/stdc++.h>
using namespace std;
bool judge(int n) {
  int t, cnt = 0;
  int s[3] = {0, 0, 0};
  while (n > 0) {
    t = n % 10;
    if (t == 3)
      s[0]++;
    else if (t == 5)
      s[1]++;
    else if (t == 7)
      s[2]++;
    n /= 10;
    cnt++;
  }
  if (s[0] && s[1] && s[2] && cnt == (s[0] + s[1] + s[2]))
    return true;
  else
    return false;
}
int main() {
  int t;
  cin >> t;
  int cnt = 0;
  for (int i = 0; i < t; i++)
    if (judge(i)) {
      cnt++;
    }
  cout << cnt;
  return 0;
}
