#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
int dfs(string s, int n) {
  if (stoi(s) > n) {
    return 0;
  }
  int res = 0;
  if (s.find('3') != s.npos && s.find('5') != s.npos && s.find('7') != s.npos) {
    res = 1;
  }
  for (char c : string("357")) {
    res += dfs(s + c, n);
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  if (n < 357) {
    cout << 0 << endl;
  } else {
    cout << dfs("0", n) << endl;
  }
  return 0;
}
static int speedUp = []() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  return 0;
}();
