#include <bits/stdc++.h>
using namespace std;
long long N;
long long dfs(long long n, long long f3, long long f5, long long f7) {
  if (n > N) return 0;
  long long res = 0;
  if (f3 && f5 && f7) res++;
  cout << n << "\n";
  for (long long i = 3; i <= 7; i += 2) {
    res += dfs(n * 10 + i, f3 || (i == 3), f5 || (i == 5), f7 || (i == 7));
  }
  return res;
}
int main(void) {
  cin >> N;
  cout << dfs(0, 0, 0, 0) << "\n";
}
