while num = gets.split(" ").map(&:to_i) do
  if(num[0] == 0 && num[1] == 0) then
    exit
  end
  num[1].times do
    printf "#"
  end
  printf "\n";
  (num[0]-2).times  do
    printf "#"
    (num[1]-2).times do
      printf "."
    end
    printf "#\n"
  end
  num[1].times do
    printf "#"
  end
  printf "\n\n";
end