#include <bits/stdc++.h>
using namespace std;
int n,m,ans,t;
int p[50005],cnt;
struct N
{
int x,y,w;
}g[200010];
int f(int x){
while(x!=p[x]){
p[x]=p[p[x]];
x=p[x];
}
return x;
}
void k()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(g[i].w>g[j].w)swap(g[i],g[j]);
for(int i=1;i<=n;i++)
p[i]=i;
for(int i=1;i<=m;i++)
{
int pos1=f(g[i].x);
int pos2=f(g[i].y);
if(pos1!=pos2)
{
cnt++;
ans+=g[i].w;
p[pos2]=pos1;
if(cnt==n)return;
}
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>g[i].x>>g[i].y>>g[i].w;
t+=g[i].w;
}
k();
cout<<t-ans;
return 0;
}