#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  if (log10(N) >= 2) {
    int flag;
    vector<int> a;
    int k;
    int p;
    for (int i = 357; i <= min(777777753, N); i++) {
      p = log10(i) + 1;
      flag = 0;
      k = i;
      a.clear();
      for (int j = 0; j < p; j++) {
        a.push_back(k % 10);
        if (k % 10 != 3 && k % 10 != 5 && k % 10 != 7) {
          flag = 1;
          break;
        }
        k /= 10;
      }
      if (flag)
        continue;
      else {
        int count3 = 0, count5 = 0, count7 = 0;
        for (int j = 0; j < a.size(); j++) {
          if (a.at(j) == 3)
            count3++;
          else if (a.at(j) == 5)
            count5++;
          else
            count7++;
        }
        if (count3 != 0 && count5 != 0 && count7 != 0) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
