#include <bits/stdc++.h>
using namespace std;
namespace {}
int main() {
  int N = 0;
  cin >> N;
  vector<int> numAll;
  for (int j = 0; j < N; ++j) {
    set<int> num;
    int tmp = j;
    for (int i = 0; i < 10; ++i) {
      num.insert(tmp % 10);
      tmp /= 10;
      if (tmp == 0) {
        break;
      }
    }
    if (num.count(1) || num.count(0) || num.count(2) || num.count(4) ||
        num.count(6) || num.count(8) || num.count(9) ||
        (num.count(7) == 0 || num.count(3) == 0 || num.count(5) == 0)) {
    } else {
      numAll.push_back(j);
    }
  }
  cout << numAll.size();
  return 0;
}
