#include <bits/stdc++.h>
using namespace std;
const int N = 10000001;
class f {
 public:
  int a, b, c, d;
};
bool a[N];
bool b[N];
vector<int> pr;
void generate() {
  for (int i = 0; i < N; i += 2) a[i] = false, b[i] = false;
  for (int i = 1; i < N; i += 2) a[i] = true, b[i] = false;
  a[1] = false;
  for (int i = 3; i * i <= N; i += 2) {
    if (a[i])
      for (int j = 2 * i; j < N; j += i) a[j] = false;
  }
  for (int i = 3; i + 8 < N; i += 2) {
    if (a[i] && a[i + 2] && a[i + 6] && a[i + 8]) {
      b[i + 8] = true;
    }
  }
  for (int i = 3; i < N; i += 2)
    if (b[i]) pr.push_back(i);
}
int main() {
  generate();
  cout << pr.size() << endl;
  int n;
  while (cin >> n && n) {
    int ans;
    for (int i = 0; i < pr.size(); i++) {
      if (pr[i] > n) break;
      ans = pr[i];
    }
    cout << ans << endl;
  }
}
