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