Each district must maintain classified elementary and secondary schools, grades 1 through 12, unless the district is exempt according to section 123A.61 or 123A.62, has made an agreement with another district or districts as provided in sections 123A.30, 123A.32, or sections 123A.35 to 123A.43, or 123A.17, subdivision 7, has received a grant under sections 123A.441 to 123A.445, or has formed a cooperative under section 123A.482. A district that has an agreement according to sections 123A.35 to 123A.43 or 123A.32 must operate a school with the number of grades required by those sections. A district that has an agreement according to section 123A.30 or 123A.17, subdivision 7, or has received a grant under sections 123A.441 to 123A.445 must operate a school for the grades not included in the agreement, but not fewer than three grades.