#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string b, temp;
  int sum = 0;
  int san, wu, qi;
  for (int i = 357; i <= n; i++) {
    int temp = i, flag = 1;
    san = 0;
    wu = 0;
    qi = 0;
    while (temp && flag) {
      int temp1 = temp % 10;
      switch (temp1) {
        case 3:
          san++;
          break;
        case 5:
          wu++;
          break;
        case 7:
          qi++;
          break;
        default:
          flag = 0;
          break;
      }
      temp /= 10;
    }
    if (flag && san && wu && qi) sum++;
  }
  cout << sum << endl;
}
