#include <bits/stdc++.h>
using namespace std;
void DFS(int n, vector<int>& a, int& ans) {
  if (to_string(n).size() == a.size()) {
    long long num = 0;
    long long mul = 1;
    for (int i = a.size() - 1; 0 <= i; i--) {
      num += a[i] * mul;
      mul *= 10;
    }
    if (num <= n) {
      map<int, int> mp;
      int count = 0;
      int zeroCount = 0;
      bool checkStart = false;
      for (int i = 0; i < a.size(); i++) {
        if (a[i] != 0) checkStart = true;
        if (!checkStart) zeroCount++;
        if (checkStart) {
          if (a[i] == 3 || a[i] == 5 || a[i] == 7) {
            count++;
            if (mp.count(a[i]))
              mp[a[i]]++;
            else
              mp[a[i]] = 1;
          }
        }
      }
      if (mp.size() == 3 && count == a.size() - zeroCount) ans++;
    }
    return;
  }
  for (int i = 0; i <= 9; i++) {
    a.push_back(i);
    DFS(n, a, ans);
    a.pop_back();
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a;
  int ans = 0;
  DFS(n, a, ans);
  cout << ans << endl;
}
