#1:????????¨???????????????????????????..#?????¢???each??§??\?????????
loop do
h, w = gets.chomp.split.map(&:to_i)
    if h == 0 && w == 0
        break
    end
line = "#" * w
puts "#{line}"
    (h - 2).times do |row|
        print "#"
        print "#{"." * (w - 2)}"
        puts "#"
    end
puts "#{line}"
puts ""
end