while true
    a, b = gets.split.map(&:to_i)
    if a == 0 and b == 0
        break
    end

    for i in 1..a
        if i == 1 or i == a
            puts "#" * b
        else
            puts "#" + ("." * (a-2)) + "#"
        end
    end
    puts ""
end
