N = 10100
ps = []

isp = Array.new(N,true)
(2..N).step 2 do |i|
  isp[i] = false
end
(3..N).step(2) do |i|
  next unless isp[i]
  ps << i
  ((i+i)..N).step(i) do |j|
    isp[j] = false
  end
end

tps = ps.each_cons(2).select{|p,q| q-p==2}

while (n=gets.to_i)!=0
  ans = tps.select{ |pair| pair[1] <= n }.last
  puts ans.join(' ')
end