#include<bits/stdc++.h>
using namespace std;
struct node{
int u;
int dis;
};
bool visited[100005];
const int INF = 99999999;
int dis[100005];
int cost[100005];
vector<node> g[1000005];
int n,m;
void spfa(){
for(int i = 0;i < n;i++){
dis[i] = INF;
}
queue<int> Q;
Q.push(0);
visited[0] = 1;
dis[0] = 0;
while(!Q.empty()){
int top = Q.front();
Q.pop();
visited[top] = 0;
for(int i = 0;i < g[top].size();i++){
int u = g[top][i].u;
int d = g[top][i].dis;
if(d + dis[top] < dis[u]){
dis[u] = d + dis[top];
cost[u] = d;
if(!visited[u]){
visited[u] = 1;
Q.push(u);
}
}
else if(d + dis[top] == dis[u]){
cost[u] = min(cost[u],d);
}
}
}
}
int main(){
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i = 0;i < m;i++){
int a,b,c;cin >> a >> b >> c;
a--;b--;
node temp;
temp.dis = c; temp.u = b;
g[a].push_back(temp);
temp.u = a; temp.dis = c;
g[b].push_back(temp);
}
spfa();
int ans = 0;
for(int i = 1;i < n;i++){
ans += cost[i];
}
cout << ans << endl;
}