while line = gets.chomp
  h,w = line.split(" ").map{|x| x.to_i}
  if h==0 && w==0
    break
  end
  for i in 1..h do
    if i==1 || i==h
      printf("%s\n","#"*w)
    else
      printf("%s\n","#"+"."*(w-2)+"#")
    end
  end
  print "\n"
end
