Juan and Mary play a two-person game where the winner gains 2 points and the loser loses 1 point. If Juan won exactly 3 games and Mary had a final score of 5 points, find the total number of games they played.

Let's think step by step and output the final answer within \boxed{}.
user