#include <bits/stdc++.h>
using namespace std;
bool is753(int x) {
  bool is3, is5, is7;
  is3 = is5 = is7 = false;
  while (x > 0) {
    int t = x % 10;
    if (t == 3)
      is3 = true;
    else if (t == 5)
      is5 = true;
    else if (t == 7)
      is7 = true;
    else
      return false;
    x /= 10;
  }
  return is3 && is5 && is7;
}
int main(int, char**) {
  int n;
  int ans = 0;
  std::cin >> n;
  int u = n % 1000;
  if (u < 357)
    ans = 0;
  else if (u < 375)
    ans = 1;
  else if (u < 537)
    ans = 2;
  else if (u < 573)
    ans = 3;
  else if (u < 735)
    ans = 4;
  else if (u < 753)
    ans = 5;
  else {
    ans = 6;
    for (int i = 3357; i < n; i++) {
      if (is753(i)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
