#include <bits/stdc++.h>
using namespace std;
string N;
int n;
int dfs(long long num, bool three, bool five, bool seven) {
  if (num >= n) {
    return 0;
  }
  int res = 0;
  if (three && five && seven) {
    cout << num << endl;
    res++;
  }
  res += dfs(num * 10 + 3, true, five, seven);
  res += dfs(num * 10 + 5, three, true, seven);
  res += dfs(num * 10 + 7, three, five, true);
  return res;
}
int main() {
  int i;
  cin >> N;
  n = atoi(N.c_str());
  cout << dfs(0, false, false, false);
  return 0;
}
