#include <bits/stdc++.h>
using namespace std;
string next3(string s) {
  int tmp = 1;
  for (int i = 0; i < s.size() && tmp == 1; i++) {
    s[i] += tmp;
    if (s[i] > '2')
      s[i] = '0';
    else if (s[i] <= '2')
      tmp = 0;
  }
  if (tmp == 1) s.push_back('0');
  return s;
}
bool is753(string s) {
  int tmp = 0;
  for (int i = 0; i < s.size(); i++) {
    tmp |= (1 << (s[i] - 48));
  }
  return tmp == 7;
}
string d2t753(int n) {
  char data[] = "0001122333";
  int log10n = log10(n) + 1;
  string s(log10n, '0');
  int t = 1;
  for (int i = 0; i < log10n && t == 1; i++) {
    if (n / (int)pow(10, i) % 10 == 0)
      n -= t * (int)pow(10, i);
    else
      t--;
  }
  for (int i = 0; i < log10n; i++) {
    s[i] = data[n / (int)pow(10, i) % 10];
  }
  for (int i = 0; i < log10n - 1; i++) {
    if (s[i] <= '0') {
      s[i + 1]--;
      s[i] = '2';
    } else
      s[i]--;
  }
  s[s.size() - 1]--;
  return s;
}
bool leftBig(string a, string b) {
  if (a.size() > b.size())
    return true;
  else if (a.size() < b.size())
    return false;
  else {
    reverse(b.begin(), b.end());
    if (a.compare(b) >= 0)
      return true;
    else
      return false;
  }
}
int main() {
  int m, n, cnt = 0;
  string s;
  vector<string> db, db2;
  cin >> n;
  string res = d2t753(n);
  reverse(res.begin(), res.end());
  string i = "210";
  if (leftBig(res, i)) {
    cout << 0 << endl;
    return 0;
  }
  do {
    db2.push_back(i);
    if (is753(i)) {
      cnt++;
      db.push_back(i);
    }
  } while (leftBig(res, i = next3(i)));
  cout << cnt << endl;
}
