Sanggeun placed N flowerpots behind K512. Taewan wants to break all of them. The pots are arranged in one line, and each pot has three integers written on it.
When Taewan breaks one pot, every pot to its right that shares at least one written number with that pot also breaks. The same rule then applies to those newly broken pots, so the breaking can continue as a chain. Therefore, breaking a single pot can cause several later pots to break.
Taewan is surprisingly lazy, so he wants to directly break as few pots as possible while still making every pot break. Compute the minimum number of pots that Taewan must break directly.

In the illustration above, if pot 2 is broken, pots 3 and 4 also break because they share the number 2. Then pot 5 breaks because it shares the number 9. Only pot 1 remains, so breaking pot 1 directly as well breaks all pots. In that situation, Taewan can break all pots by directly breaking two pots.
The first line contains the number of flowerpots N (1 <= N <= 300,000).
Each of the next N lines contains three integers Ai, Bi, and Ci, the numbers written on the corresponding pot in order (1 <= Ai, Bi, Ci <= 1,000,000).
Print the minimum number of pots that Taewan must break directly.