#include <bits/stdc++.h>
using namespace std;
long long int N;
int dfs(int depth, long long int a) {
  int counter = 0;
  if (depth == 9) return 0;
  if (10 ^ depth * 3 + a < N) {
    counter++;
    counter += dfs(depth + 1, pow(10, depth) * 3 + a);
  }
  if (10 ^ depth * 5 + a < N) {
    counter++;
    counter += dfs(depth + 1, pow(10, depth) * 5 + a);
  }
  if (10 ^ depth * 7 + a < N) {
    counter++;
    counter += dfs(depth + 1, pow(10, depth) * 7 + a);
  }
  return counter;
}
int main() {
  cin >> N;
  int ans = dfs(0, 0LL);
  cout << ans;
}
