#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int tmp = i;
    bool tmpf = true;
    int c3 = 0, c5 = 0, c7 = 0;
    while (tmp != 0) {
      int index = tmp % 10;
      tmp /= 10;
      if (index == 3) {
        c3++;
        continue;
      } else if (index == 5) {
        c5++;
        continue;
      } else if (index == 7) {
        c7++;
        continue;
      } else {
        tmpf = false;
        break;
      }
    }
    if (tmpf && c3 > 0 && c5 > 0 && c7 > 0) {
      ans++;
    }
  }
  cout << ans;
}
