#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void rec(int n, vector<string> &v, string x) {
  if (n == 0) {
  } else {
    string kouho[3] = {"7", "5", "3"};
    for (int i = 0, i_len = (3); i < i_len; ++i) {
      string tmp = x + kouho[i];
      v.push_back(tmp);
      rec(n - 1, v, tmp);
    }
  }
}
bool Find(string s) {
  if ((s.find("7") != string::npos) and (s.find("5") != string::npos) and
      (s.find("3") != string::npos)) {
    return true;
  } else {
    return false;
  }
}
int main() {
  long long N;
  int cnt = 0;
  string tmp2;
  cin >> N;
  int digit = floor(log10(N)) + 1;
  vector<string> List;
  rec(digit, List, "");
  for (int i = 0, i_len = (List.size()); i < i_len; ++i) {
    tmp2 = List[i];
    if (((stoi(tmp2)) <= N) and Find(tmp2)) {
      cnt += 1;
    }
  }
  cout << cnt << endl;
}
