#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x;
  long long int n = 0, n3 = 0, n5 = 0, n7 = 0, n0 = 0, n10, c;
  cin >> x;
  for (int i = 357; i <= x; i++) {
    c = i;
    n10 = 10;
    n3 = 0;
    n5 = 0;
    n7 = 0;
    n0 = 0;
    while (c > 0) {
      if (c % 10 == 3) {
        n3++;
      } else if (c % 10 == 5) {
        n5++;
      } else if (c % 10 == 7) {
        n7++;
      } else {
        n0++;
        break;
      }
      c = (c - (c % 10)) / 10;
    }
    if (n3 > 0 && n5 > 0 && n7 > 0 && n0 == 0) {
      n++;
    }
  }
  cout << n << endl;
}
