while 1 do
    h,w = gets.chomp.split.map(&:to_i)
    if h == 0 && w == 0
        break
    end
    h.times do |i|
        if i == 0 || i == h-1
            puts "#"*w
        else
            puts "#"+ "."*(w-2) +"#"
        end
    end
    puts
end