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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; typedef long long ll; int an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P; const int xx[4]={1,-1,0,0}, yy[4]={0,0,1,-1}; struct tp{int x,y; ll cs;};
struct unf {
  vector<int> v; unf(int n){v.resize(n); for(int i=0;i<n;i++) v[i]=i;}
  int root(int x) { if (v[x]==x) return x; return v[x]=root(v[x]);}
  void unite(int x,int y) {int p=root(x), q=root(y); if (p==q) return; v[p]=q;}
  bool same(int x, int y) {return root(x)==root(y);}
  void print() {for(int x:v) cout<<x<<" "; cout<<endl;}
};

int main(){
  int n,m; cin>>n>>m; //if (m==0) return puts("0")*0;
  tp t[m]; for(int i=0;i<m;i++) cin>>t[i].x>>t[i].y>>t[i].cs;
  sort(t,t+m,[](tp a, tp b){return a.cs<b.cs;});

  unf u(n); ll an=0;
  for(int i=0;i<m;i++) {
    //cout<<t[i].x<<" "<<t[i].y<<" "<<t[i].cs<<endl;
    if (!u.same(t[i].x, t[i].y)) {an+=t[i].cs; u.unite(t[i].x, t[i].y);}
  }
  cout<<an<<endl;
}