After little more than a year in office as vice president, Elbridge Gerry of Massachusetts died. While the vice president dying was not seen as particularly unusual, Elbridge himself had been chosen to replace George Clinton who had died in office as well, the Vice President could not be replaced until the next election.
This meant that from 1814 to 1817 Madison has no Vice President and that in the event of his death, the Senate Pro Tempore would succeed to the office of the Presidency. In this case, that man would be Senator Joseph Varnum of Massachusetts.
Now, suppose Elbridge dies on cue and a few weeks later Madison dies of unrelated causes. Joseph Varnum becomes President of the United States sometime in January.
What happens now?