#include <bits/stdc++.h>
using namespace std;
void fnInput(int& rnMaxNum) { cin >> rnMaxNum; }
bool fnDgt753_Check(int nCheck) {
  int nDgt3Cnt = 0;
  int nDgt5Cnt = 0;
  int nDgt7Cnt = 0;
  while (nCheck) {
    int n1stPlace = nCheck % 10;
    if (n1stPlace == 3)
      nDgt3Cnt++;
    else if (n1stPlace == 5)
      nDgt5Cnt++;
    else if (n1stPlace == 7)
      nDgt7Cnt++;
    else
      return false;
    nCheck /= 10;
  }
  if (nDgt3Cnt > 0 && nDgt5Cnt > 0 && nDgt7Cnt > 0)
    return true;
  else
    return false;
}
int fnDgt753_Count(int nMaxNum) {
  int nDgt753Cnt = 0;
  for (int n = 357; n <= nMaxNum; n++)
    if (fnDgt753_Check(n)) nDgt753Cnt++;
  return nDgt753Cnt;
}
int main() {
  int nMaxNum;
  fnInput(nMaxNum);
  cout << fnDgt753_Count(nMaxNum) << endl;
  return 0;
}
