#include <bits/stdc++.h>
using namespace std;
int N;
int arr[3] = {3, 5, 7};
string st = "357";
int solve(int n) {
  int res = 1;
  if (n > N) return 0;
  for (int i = 0; i < 3; i++) {
    if (to_string(n).find(st[i]) == string::npos) res = 0;
  }
  for (int i = 0; i < 3; i++) res += solve(n * 10 + arr[i]);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  cout << solve(0) << '\n';
  return 0;
}
