#include <bits/stdc++.h>
using namespace std;
bool is_753(int num) {
  bool s = false, f = false, t = false;
  for (; num > 0; num /= 10) {
    switch (num % 10) {
      case 3:
        t = true;
        break;
      case 5:
        f = true;
        break;
      case 7:
        s = true;
        break;
      default:
        return false;
    }
  }
  return s && f && t;
}
int main() {
  int N;
  cin >> N;
  int out = 0;
  for (int i = 357; i <= N; i++) {
    if (is_753(i) == true) {
      out++;
    }
  }
  cout << out << endl;
}
