#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, tmp, count = 0;
  bool a, b, c;
  cin >> n;
  for (int i = 100; i <= n; i++) {
    tmp = i;
    a = b = c = false;
    while (tmp != 0) {
      if (tmp % 10 == 3)
        a = true;
      else if (tmp % 10 == 5)
        b = true;
      else if (tmp % 10 == 7)
        c = true;
      else {
        a = b = c = false;
        break;
      }
      tmp /= 10;
    }
    if (a && b && c) count++;
  }
  cout << count << endl;
}
