#include <bits/stdc++.h>
using namespace std;
int acount = 0;
int bcount = 0;
int ccount = 0;
void dfs(long long N, long long v, vector<long long> &all) {
  if (v > N)
    return;
  else {
    if (acount != 0 && bcount != 0 && ccount != 0) all.push_back(v);
    acount++;
    dfs(N, 10 * v + 7, all);
    bcount++;
    acount--;
    dfs(N, 10 * v + 5, all);
    ccount++;
    bcount--;
    dfs(N, 10 * v + 3, all);
  }
}
int main() {
  long long N;
  cin >> N;
  vector<long long> t;
  dfs(N, 7, t);
  acount = 0;
  bcount = 0;
  ccount = 0;
  dfs(N, 5, t);
  acount = 0;
  bcount = 0;
  ccount = 0;
  dfs(N, 3, t);
  long long k = t.size();
  cout << k << endl;
}
