#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long N;
void dfs(bool f3, bool f5, bool f7, long long now) {
  if (now > N) {
    return;
  }
  if (f3 && f5 && f7 && now <= N) {
    ans++;
    return;
  }
  dfs(true, f5, f7, 10 * now + 3);
  dfs(f3, true, f7, 10 * now + 5);
  dfs(f3, f5, true, 10 * now + 7);
  return;
}
int main() {
  cin >> N;
  dfs(false, false, false, 0LL);
  cout << ans << endl;
  return 0;
}
