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 ans = Array.new(H) { Array.new(N / H, 0) } y = 0 x = 0 N.divisor_list.reverse_each do |v| next if v == N h = v / W w = v % W if h > 0 y.upto(y + h - 1) do |cy| 0.upto(W - 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 puts ans.map { |row| row.join(' ') }