class Solver
  def initialize

    loop do
      h, w = gets.chomp.split(' ').map(&:to_i)

      break if h.zero? && w.zero?

      puts '#' * w

      (h-2).times do
        puts ['#','.' * (w-2),'#'].join
      end

      puts '#' * w

      puts
    end
  end
end

Solver.new