The latter. The Presidential Succession Act provides that
Subsections (a) and (b) refer to the primary statutory successors, the Speaker and the President pro tem. (A similar provision in subsection (d)(2) likewise limits the term of the secondary statutory successors, the Cabinet officers.)
If there were Presidential vacancies both before and after Inauguration Day, thus occurring in separate terms, then each vacancy is filled independently. The successor who fills the first vacancy serves until Inauguration Day, after which a new succession occurs, elevating the then-Speaker to the Presidency for the new term.