The first president not from Virginia or Massachusetts was John Adams, who served as the second president of the United States from 1797 to 1801. However, if we consider the question strictly in terms of being the first president from a state other than these two, then it would be Martin Van Buren, who became the eighth president in 1837 and hailed from New York.
This is significant because the first several U.S. presidents were primarily from Virginia or Massachusetts, reflecting the early political power dynamics in the fledgling nation. With Van Buren’s presidency, it marked a shift towards leaders from different states taking on a more prominent role in the nation’s leadership.