#include<bits/stdc++.h>
using namespace std;
priority_queue<pair<long long,long long> >q;
vector<long long>ver[5010],edge[5010];
bool v[5010];
long long d[5010];
long long n,m;
void add(long long x,long long y,long long z){
	ver[x].push_back(y);edge[x].push_back(z);
}
void init(){
	cin>>n>>m;
	for(long long i=1;i<=m;i++){
		long long a,b,c;
		cin>>a>>b>>c;
		add(a,b,c);add(b,a,c);
	}
}

void work(){
	memset(d,0x3f,sizeof(d));
	memset(v,0,sizeof(v));
	long long ans=0;
	d[1]=0;
	q.push(make_pair(0,1));
	int cnt=0;
	while(q.size()){
		long long x=q.top().second;
		q.pop();
		if(v[x])continue;
		v[x]=1;
		cnt++;
		for(int i=ver[x].size()-1;i>=0;i--){
		
			int y=ver[x][i],z=edge[x][i];
			if(!v[y] &&(z<d[y])){
				d[y]=z;
				q.push(make_pair(-d[y],y));
			}
		}
		
		
	}
for(int i=2;i<=n;i++)ans+=d[i];
if(cnt==n)cout<<ans;
else cout<<"orz";


}

int main(){
init();
work();

}