while true
    h,w = gets.chomp.split.map(&:to_i)
    
    if h==0 && w==0 then
        break
    end
    
    h.times do |y|
        if y==0 || y==h-1 then
            puts "#"*w
        else
            print("#","."*(w-2),"#\n")
        end
    end
    print("\n")
end