#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, a, k, n3, n5, n7, ans = 0;
  cin >> n;
  for (a = 357; a <= n; a++) {
    k = a;
    n3 = n5 = n7 = 0;
    while (k) {
      if (k % 10 == 3)
        n3++;
      else if (k % 10 == 5)
        n5++;
      else if (k % 10 == 7)
        n7++;
      else
        break;
      k /= 10;
    }
    if (k == 0 && n3 && n5 && n7) ans++;
  }
  cout << ans << endl;
  return 0;
}
