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