#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i <= n; ++i) {
    int x = i;
    bool t = false, f = false, s = false;
    while (x != 0) {
      int a = x % 10;
      if (a == 3)
        t = true;
      else if (a == 5)
        f = true;
      else if (a == 7)
        s = true;
      else {
        t = false;
        break;
      }
      x /= 10;
    }
    if (t == true && f == true && s == true) {
      ++ans;
    }
  }
  cout << ans << endl;
}
