CF17B Hierarchy

Description

Nick's company employed $ n $ people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are $ m $ applications written in the following form: «employee $ a_{i} $ is ready to become a supervisor of employee $ b_{i} $ at extra cost $ c_{i} $ ». The qualification $ q_{j} $ of each employee is known, and for each application the following is true: $ q_{ai}>q_{bi} $ . Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.

Input Format

The first input line contains integer $ n $ ( $ 1

Output Format

Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.

Explanation/Hint

In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.