#include <bits/stdc++.h>
using namespace std;
bool xianqi(int n) {
  int n3 = 0, n5 = 0, n7 = 0, nm = 0;
  while (n > 0) {
    nm++;
    if (n % 10 == 3) n3++;
    if (n % 10 == 5) n5++;
    if (n % 10 == 7) n7++;
    n /= 10;
  }
  if (n3 > 0 && n5 > 0 && n7 > 0 && (n3 + n5 + n7) == nm)
    return true;
  else
    return false;
}
int main() {
  int t, i, sum = 0;
  cin >> t;
  for (i = 357; i <= t; i++)
    if (xianqi(i)) {
      sum++;
    }
  cout << sum << endl;
  return 0;
}
