loop do
    h, w = gets.chomp.split.map(&:to_i)
    if h == 0 && w == 0
        break
    end
    puts "#{"#" * w}"
    (h - 2).times do |line|
        line = "#" + "." * (w - 2) + "#"
        puts "#{line}"
    end
    puts "#{"#" * w}"
    puts ""
end