while true
  h, w = gets.chomp.split.map(&:to_i)
  break if h == 0 && w == 0
  for i in 1..h
    if i == 1 || i == h
      puts "#" * w
    else
      puts "#" + "." * (w - 2) + "#"
    end
  end
  print "\n"
end