lines = STDIN.read.split("\n")
lines.each do |line|
  h, w = line.split(" ").map(&:to_i)
  break if h == 0 && w == 0
  puts "#" * w
  (h - 2).times do |i|
    puts ["#", "." * (w - 2), "#"].join('')
  end
  puts "#" * w
  print "\n"
end