#include <bits/stdc++.h>
using namespace std;
bool is753(long val) {
  char c[11];
  int flg[3];
  long len, ii;
  sprintf(c, "%ld", val);
  len = strlen(c);
  memset(flg, 0, sizeof(flg));
  for (ii = 0; ii <= 2; ii++) {
    flg[ii] = 0;
  }
  for (ii = 0; ii < len; ii++) {
    if (c[ii] == '7') {
      flg[0]++;
    } else if (c[ii] == '5') {
      flg[1]++;
    } else if (c[ii] == '3') {
      flg[2]++;
    } else {
      return false;
    }
  }
  for (ii = 0; ii <= 2; ii++) {
    if (flg[ii] == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  long n, ii, num;
  num = 0;
  cin >> n;
  for (ii = 0; ii <= n; ii++) {
    if (is753(ii)) {
      num++;
    }
  }
  cout << num << endl;
  return 0;
}
