#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, ans = 0;
void dfs(ll num, int thr, int fiv, int sev) {
  if (num > N) return;
  if (thr && fiv && sev) ans++;
  dfs(10 * num + 3, 1, 0, 0);
  dfs(10 * num + 5, 0, 1, 0);
  dfs(10 * num + 7, 0, 0, 1);
}
int main() {
  cin >> N;
  dfs(3, 1, 0, 0);
  dfs(5, 0, 1, 0);
  dfs(7, 0, 0, 1);
  cout << ans << endl;
  return 0;
}
