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 CPP):

Solution:
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string.h>

struct Edge
{
	int vx_a;
	int vx_b;
	int w;

	bool operator < (const Edge& e) const{
		return w > e.w;
	}
};

const int MAXN = 10000;
int uset[MAXN];
int V, E;
std::priority_queue<Edge> eq;

void init() {
	memset(uset, -1, sizeof(uset));
}

int find_root(int x) {
	if (uset[x] == -1) {
		return x;
	}
	else {
		int root = find_root(uset[x]);
		uset[x] = root;
		return root;
	}
}

void unite(int x, int y) {
	int rx = find_root(x);
	int ry = find_root(y);
	if (rx != ry) {
		uset[rx] = ry;
	}
}

bool same(int x, int y) {
	return find_root(x) == find_root(y);
}

int mst_cost() {
	int cost = 0;
	int v = V - 1;
	while (v) {
		Edge edge = eq.top();
		if (!same(edge.vx_a, edge.vx_b)) {
			unite(edge.vx_a, edge.vx_b);
			cost += edge.w;
			v--;
		}
		eq.pop();
	}
	return cost;
}

int main() {
	scanf("%d%d", &V, &E);
	init();
	for (int i = 0; i < E; i++) {
		int s, t, w;
		scanf("%d%d%d", &s, &t, &w);
		eq.push({ s, t, w });
	}
	printf("%d\n", mst_cost());

	return 0;
}