#include <bits/stdc++.h>
using namespace std;
bool check(int i) {
  int a = 0, b = 0, c = 0;
  while (i != 0) {
    if (i % 10 == 3)
      a++;
    else if (i % 10 == 5)
      b++;
    else if (i % 10 == 7)
      c++;
    else
      return false;
    i /= 10;
  }
  if (a > 0 && b > 0 && c > 0)
    return true;
  else
    return false;
}
int ans;
int main() {
  int start = clock();
  int a;
  cin >> a;
  for (int i = 357; i <= a;) {
    if (check(i)) ans++;
    if (i % 10 == 7)
      i += 6;
    else
      i += 2;
  }
  cout << ans << endl;
  return 0;
}
