#include <bits/stdc++.h>
using namespace std;
vector<string> F;
vector<int> sft;
void f(string s) {
  if (s.size() == 10) return;
  F.push_back(s);
  f(s + "3");
  f(s + "5");
  f(s + "7");
  return;
}
void judge(string s) {
  bool j = false;
  for (int i = 0; i < (int)(s.size()); ++i)
    if (s[i] == '3') j = true;
  if (!j) return;
  j = false;
  for (int i = 0; i < (int)(s.size()); ++i)
    if (s[i] == '5') j = true;
  if (!j) return;
  j = false;
  for (int i = 0; i < (int)(s.size()); ++i)
    if (s[i] == '7') j = true;
  if (!j) return;
  int S = stoi(s);
  sft.push_back(S);
  return;
}
int main() {
  int N;
  cin >> N;
  f("3");
  f("5");
  f("7");
  for (auto x : F) judge(x);
  sort(sft.begin(), sft.end());
  int cnt = 0;
  for (int x : sft)
    if (x < N) ++cnt;
  cout << cnt << endl;
  return 0;
}
