#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
int n,m,ans,cnt,tot;
inline void read(int& qwq){
int awa = 0,w = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') w = -1;ch = getchar();}
while(ch >= '0' && ch <= '9'){awa = awa * 10 + ch - '0';ch = getchar();}
qwq = awa * w;
}
bool vis[maxn];
int to[maxn*2],vlu[maxn*2],nxt[maxn*2],head[maxn];
priority_queue<pair<int,int> > p;
inline void insert(int u,int v,int w){
to[++tot] = v;
vlu[tot] = w;
nxt[tot] = head[u];
head[u] = tot;
}
void prim(int root){
p.push(make_pair(0,root));
while(!p.empty()){
int u=p.top().second,res=p.top().first;
p.pop();
if(vis[u]) continue;
res *= -1,ans += res;
cnt++;
vis[u] = 1;
for(int i=head[u];i;i=nxt[i]){
int v=to[i],w=vlu[i];
if(vis[v]) continue;
p.push(make_pair(-w,v));
}
}
}
int main() {
read(n),read(m);
int u,v,w;
for(int i=1; i<=m; i++) {
read(u),read(v),read(w);
insert(u,v,w);
insert(v,u,w);
}
prim(1);
if(cnt == n) cout<<ans;
else cout<<"orz";
return 0;
}