#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<int, vector<int>, greater<int> > spqint;
typedef priority_queue<long long, vector<long long>, greater<long long> > spqll;
typedef priority_queue<int, vector<int>, less<int> > bpqint;
typedef priority_queue<long long, vector<long long>, less<long long> > bpqll;
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int N;
vector<string> vec;
vector<string> dc = {"3", "5", "7"};
void dfs_list(int d, string s) {
  vec.push_back(s);
  if (d == N) {
    return;
  }
  for (int i = 0; i < dc.size(); i++) {
    dfs_list(d + 1, s + dc[i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  N = 9;
  int n;
  cin >> n;
  dfs_list(0, "");
  vector<long long> vv;
  for (int(i) = 0; (i) < (int)((long long)vec.size()); i++) {
    int cnt3 = 0;
    int cnt5 = 0;
    int cnt7 = 0;
    for (int(j) = 0; (j) < (int)((long long)vec[i].size()); j++) {
      if (vec[i][j] == '3') {
        cnt3++;
      } else if (vec[i][j] == '5') {
        cnt5++;
      } else {
        cnt7++;
      }
    }
    if (cnt7 != 0 && cnt3 != 0 && cnt5 != 0) {
      vv.push_back(stol(vec[i]));
    }
  }
  sort((vv).begin(), (vv).end());
  auto itr = lower_bound((vv).begin(), (vv).end(), n);
  int ans = distance(vv.begin(), itr);
  cout << ans << endl;
  return 0;
}
