#include<bits/stdc++.h>
using namespace std;
typedef int ll;

ll d[5010],mp[5010][5010];
bool v[5010];
ll i,j,n,m,t,k;

int main() {
	cin>>n>>m;
	memset(mp,0x3f,sizeof(mp));
	memset(d,0x3f,sizeof(d));
	memset(v,0,sizeof(v));
	ll a,b,c;

	for(i=1; i<=m; i++) {
		cin>>a>>b>>c;

		mp[a][b]=min(mp[a][b],c);

		mp[b][a]=mp[a][b];

	}

	d[1]=0;

	for(i=1; i<n; i++) {
		ll x=0;
		for(j=1; j<=n; j++)

			if(!v[j]&&(x==0||d[j]<d[x]))x=j;

		v[x]=1;
		for(j=1; j<=n; j++)

			if(!v[j])d[j]=min(d[j],mp[x][j]);

	}

	ll ans=0;
	for(i=2; i<=n; i++)
		ans+=d[i];
	
	if(ans>99999999)cout<<"orz";
	else cout<<ans;
	
	
}