You are given an undirected weighted graph. Compute the total weight of a Minimum Spanning Tree (MST) of the graph.

If the graph is disconnected, it has no spanning tree; in that case output -1.

Input

The first line contains integers nn and mm, the number of nodes and edges.

The following mm lines each contain three integers aa, bb, and cc, describing an undirected edge between aa and bb with weight cc.

Nodes are numbered from 11 to nn.

Output

Output a single integer: the weight of an MST, or -1 if none exists.

Constraints

  • 1n1051 \le n \le 10^5
  • 0m2×1050 \le m \le 2 \times 10^5
  • 1a,bn1 \le a, b \le n
  • 1c1091 \le c \le 10^9

Example 1

Input 1
3 4
1 2 5
1 3 6
2 3 2
2 1 3
Output 1
5
Explanation

One MST uses edges of weights 33 and 22, for a total of 55.

Example 2

Input 2
4 2
1 2 1
3 4 1
Output 2
-1

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.