#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll x, y, z, l, m, n, r, q, k;
ll ans = 0;
void dfs(ll num) {
  if (num > n) return;
  string s = to_string(num);
  int cnt[8]{0};
  while (num) {
    if (num % 10 == 3)
      cnt[3]++;
    else if (num % 10 == 5)
      cnt[5]++;
    else if (num % 10 == 7)
      cnt[7]++;
    num /= 10;
  }
  if (cnt[3] and cnt[5] and cnt[7]) ans++;
  dfs(num * 10 + 3);
  dfs(num * 10 + 5);
  dfs(num * 10 + 7);
}
void solve() {
  cin >> n;
  dfs(0);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  int test;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
