#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF + 7;
const ll LINF = 1e18;
int N;
int num[3] = {3, 5, 7};
int dfs(int n) {
  int res = 0;
  if (n > N) return 0;
  int tmp = n;
  bool three = false, five = false, seven = false;
  while (tmp) {
    if (tmp % 10 == 3) three = true;
    if (tmp % 10 == 5) five = true;
    if (tmp % 10 == 7) seven = true;
    tmp /= 10;
  }
  if (three && five && seven) ++res;
  for (int i = 0; i < 3; ++i) res += dfs(n * 10 + num[i]);
  return res;
}
int main() {
  cin >> N;
  cout << dfs(0) << endl;
}
