#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long MOD = 1000000007;
const int INF = 1 << 29;
const int MAX = 510000;
int ans;
int N;
vector<int> que = {7, 5, 3};
vector<int> cnt(3);
void dfs(int sum) {
  cnt.assign(3, 0);
  int tmp = sum;
  while (tmp > 0) {
    if (tmp % 10 == 7)
      cnt[0]++;
    else if (tmp % 10 == 5)
      cnt[1]++;
    else
      cnt[2]++;
    tmp /= 10;
  }
  if (sum <= N && cnt[0] != 0 && cnt[1] != 0 && cnt[2] != 0) {
    ans++;
  }
  if (sum >= N) return;
  for (int q : que) {
    sum = sum * 10 + q;
    dfs(sum);
    sum /= 10;
  }
}
int main() {
  cin >> N;
  ans = 0;
  dfs(0);
  cout << ans << endl;
}
