while line = gets
  h, w = line.split(' ').map(&:to_i)
  break if h == 0 &&  w == 0
  top_bottom = w.times.map{|i| "#"}.join
  middle = "#" + (w - 2).times.map{|i| "."}.join + "#"
  puts top_bottom
  (h - 2).times each{|i| puts middle}
  puts top_bottom
  puts ""
end
