class Integer def divisor_list require 'prime' return [] if self <= 0 return [1] if self == 1 prime_division.map.with_index { |(base, k), i| s = i.zero? ? 0 : 1 (s..k).map { |n| base ** n } }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort end end N, H = gets.split.map(&:to_i) if N % H != 0 puts -1 exit end W = N / H height, width = [H, W].sort ans = Array.new(height) { Array.new(width, 0) } y = 0 x = 0 N.divisor_list.reverse_each do |v| next if v == N h = v / width w = v % width if h > 0 y.upto(y + h - 1) do |cy| 0.upto(width - 1) do |cx| ans[cy][cx] = v end end else w.times do ans[y][x] = v x += 1 end end if h > 0 y += h x = 0 end end if H > W ans = ans.transpose end puts ans.map { |row| row.join(' ') }