#include <bits/stdc++.h>
using namespace std;
bool isSIGOSAN(int n) {
  int ket = 0;
  int thrcnt = 0, fifcnt = 0, sevcnt = 0, othcnt = 0;
  int tmp = 0, tmp2 = n;
  while (tmp2 != 0) {
    tmp2 /= 10;
    ket++;
  }
  while (othcnt == 0) {
    tmp = n % 10;
    if (tmp == 7)
      sevcnt++;
    else if (tmp == 5)
      fifcnt++;
    else if (tmp == 3)
      thrcnt++;
    else
      othcnt++;
    n /= 10;
    ket--;
    if (ket == 0) {
      if (sevcnt >= 1 && fifcnt >= 1 && thrcnt >= 1 && othcnt == 0)
        return true;
      else
        return false;
    }
  }
  return false;
}
int main() {
  int n;
  int cnt = 0;
  cin >> n;
  for (int i = 356; i <= n; i++)
    if (isSIGOSAN(i)) cnt++;
  cout << cnt << endl;
}
