#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int num3 = 0, num5 = 0, num7 = 0, numother = 0;
    int num = i;
    while (num / 10 > 0) {
      if (num % 10 == 7)
        num7++;
      else if (num % 10 == 5)
        num5++;
      else if (num % 10 == 3)
        num3++;
      else
        numother++;
      num = num / 10;
    }
    if (num7 >= 1 && num5 >= 1 && num3 >= 1 && numother == 0) ans++;
  }
  cout << ans << endl;
}
