Multi Ending Story
You are a programmer who loves bishojo games (a sub-genre of dating simulation games). A game, which is titled "I * C * P * C!" and was released yesterday, has arrived to you just now. This game has multiple endings. When you complete all of those endings, you can get a special figure of the main heroine, Sakuya. So, you want to hurry and play the game! But, let's calm down a bit and think how to complete all of the endings in the shortest time first.
In fact, you have a special skill that allows you to know the structure of branching points of games. By using the skill, you have found out that all of the branching points in this game are to select two choices "Yes" or "No", and once a different choice is taken the branched stories flow to different endings; they won't converge any more, like a binary tree. You also noticed that it takes exactly one minute to proceed the game from a branching point to another branching point or to an ending. In addition, you can assume it only takes negligible time to return to the beginning of the game ("reset") and to play from the beginning to the first branching point.
The game has an additional feature called "Quick Save", which can significantly reduce the playing time for completion. The feature allows you to record the point where you are currently playing and return there at any time later. You can record any number of times, but you can hold only the last recorded point. That is, when you use Quick Save, you overwrite the previous record. If you want to return to the overwritten point, you must play the game from the beginning once again.
Well, let's estimate how long it will take for completing all of the endings in the shortest time.
Input
A data set is given in the following format.
N
2 ≤ N ≤ 500,000
N−1
i
Yes_i
No_i
i+1 ≤ Yes_i, No_i ≤ N
Yes_i=N
No_i=N
N−1
Yes_i
No_i
The first line of the data set contains one integer (), which denotes the number of the endings in this game. The following lines describe the branching points. The -th line describes the branching point of ID number i and contains two integers and (), which denote the ID numbers of the next branching points when you select Yes or No respectively. means that you can reach an ending if you select Yes, and so for . The branching point with ID 1 is the first branching point. The branching points with ID between 2 and (inclusive) appear exactly once in 's and 's.
Output
Print the shortest time in a line.