So it should be general-the first class is arranged in physical education class-the last class is arranged in math class+the first class is arranged in physical education class, and the last class is arranged in math class.
The total number is p (6 6,6) = 6× 5× 4× 3× 2×1= 720.
In the first section, the ranking of physical education class is P (5 5,5) = 5× 4× 3× 2×1=120.
The last math class is P (5 5,5) = 5× 4× 3× 2×1=120.
Physical education class was arranged in the first section, and math class was arranged in the last section. P (4,4) = 4× 3× 2× 1 = 24。
Therefore, there is an arrangement of 720-120-120+24 = 504, which excludes physical education in the first section and mathematics in the last section.