1 #define IO std::ios::sync_with_stdio(0)
2 #include <bits/stdc++.h>
3 #define pb push_back
4 using namespace std;
5 typedef long long ll;
6 const int N=2e5+5;
7 const int inf=2147483647;
8
9 int n,m;
10
11 struct node{
12 int u,v,w;
13 }a[N];
14
15 int fa[N];
16
17 int find(int x){
18 return x==fa[x]?x:fa[x]=find(fa[x]);
19 }
20
21 bool cmp(node p,node q){
22 return p.w<q.w;
23 }
24
25 int Kruskal(){
26 sort(a+1,a+1+m,cmp);
27 int cnt=0,ans=0;
28 for(int i=1;i<=n;i++)fa[i]=i;
29 for(int i=1;i<=m;i++){
30 int x=a[i].u;
31 int y=a[i].v;
32 x=find(x);
33 y=find(y);
34 if(x!=y){
35 ans+=a[i].w;
36 fa[x]=y;
37 cnt++;
38 }
39 if(cnt==n-1)return ans;
40 }
41 return -1;
42
43 }
44
45 int main(){
46 IO;
47 cin>>n>>m;
48 for(int i=1;i<=m;i++){
49 cin>>a[i].u>>a[i].v>>a[i].w;
50 }
51 int ans=Kruskal();
52 if(ans==-1)cout<<"orz"<<endl;
53 else cout<<ans<<endl;
54 }