#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a, b, c;
  int k, m, l, x;
  int cnt = 0;
  for (int i = 357; i <= n; i += 2) {
    a = 0;
    b = 0;
    c = 0;
    k = 1;
    m = i;
    l = i;
    for (;;) {
      if (m / 10 != 0) {
        m /= 10;
        k++;
      } else {
        break;
      }
    }
    for (int j = 0; j < k; j++) {
      x = l % 10;
      if (x == 3) {
        a++;
      } else if (x == 5) {
        b++;
      } else if (x == 7) {
        c++;
      }
      l /= 10;
    }
    if (a != 0 && b != 0 && c != 0 && a + b + c == k) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
