while true
  h,w = gets.chomp.split.map {|e| e.to_i}
  break if (h == 0 && w == 0)
  h.times {|i|
    if (i ==0 || i == h-1)
      puts "#"*w
    else
      puts "#" + ". "*(w-2) + "#"
    end
  }
  puts ""
end