Problem: Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).

Constraints

* 1 ≤ |V| ≤ 10,000
* 0 ≤ |E| ≤ 100,000
* 0 ≤ wi ≤ 10,000
* The graph is connected
* There are no parallel edges
* There are no self-loops

Input


|V| |E|
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1


, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target verticess of i-th edge (undirected) and wi represents the weight of the i-th edge.

Output

Print the sum of the weights of the Minimum Spanning Tree.

Examples

Input

4 6
0 1 2
1 2 1
2 3 1
3 0 1
0 2 3
1 3 5


Output

3


Input

6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6


Output

5

Solution (in PYTHON3):

Solution:
from sys import stdin
input = stdin.readline

from collections import defaultdict

MAX = 10000
infty = -1

class Disjoint():
    def __init__():
        return

def getRoot(x):
    global v
    for _ in range(v+1):
        if dic[x]["parent"] == x:
            return x
        x = dic[x]["parent"]

def unite(x, y):
    r = getRoot(x)
    l = getRoot(y)
    a = dic[r]["rank"]
    b = dic[l]["rank"]

    if a == b:
        dic[r]["rank"] += 1
        dic[l]["parent"] = r

    elif a > b:
        dic[l]["rank"] = 0
        dic[l]["parent"] = r

    elif a < b:
        dic[r]["rank"] = 0
        dic[r]["parent"] = l

lines = stdin.readlines()
dic = defaultdict()
v, e = map(int, lines[0].split())
#E = [[lines[i+1].split()[0], lines[i+1].split()[1], lines[i+1].split()[2],] for i in range(e)]
E = [ list(map(int, lines[i+1].split())) for i in range(e)]
E = sorted(E, key=lambda x:x[2])

# Eの要素を整列
E = sorted(E, key=lambda x:x[2])
# V に対応した互に素な集合Sを生成する
for _ in range(v):
    dic[_] = {"rank":0,"parent":_}
# 辺の集合Kを空にする
k = 0
total = 0

for edge in E:
    if getRoot(edge[0]) != getRoot(edge[1]):
        unite(edge[0], edge[1])
        k += 1
        total += edge[2]

print(total)