ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if h == 0 && w == 0
  h.times do |i|
    case i
      when 0, (h - 1)
        puts "#{'#' * w}"
      else
        puts "#" + "." * (w - 2) + "#"
     end
  end
  puts
end