while true
    rect = gets.split.map(&:to_i)
    break if (rect[0] == 0 && rect[1] == 0)
    cen = rect[0]-2
    cen2 = rect[1]-2
    
    puts '#'*rect[1]
    
    cen.times do
        print "#"
        puts '#'*cen2
        print "#"
        puts
    end
    
    puts '#'*rect[1]
    
end