loop do
  a = gets.split(" ").map{|x| x.to_i}
  h = a[0]
  w = a[1]
  break if h + w == 0
  for i in 1..h do
    for j in 1..w do
      if i == 1 || i == h
        printf "#"
      elsif j ==1 || j == w
        printf "#"
      else
        printf "."
      end
    end
    puts
  end
  puts
end
