#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int N = 10010, M = 100010, INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
int h[N], e[M], ne[M], w[M], idx;
bool st[N];
int dist[N];
int cost[N];
void add(int a, int b, int c){
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx ++;
}
void dijkstra(int p){
priority_queue<PII, vector<PII>, greater<PII>> heap;
dist[p] = 0;
cost[p] = 0;
heap.push({dist[p], p});
while(heap.size()){
auto t = heap.top();
heap.pop();
int u = t.second;
//cout << t.first << " " << t.second << endl;
if (st[u]) continue;
st[u] = true;
for (int i = h[u]; ~i; i = ne[i]){
int j = e[i], l = w[i];
// cout << l << endl;
if (st[j]) continue;
if (dist[u] + l < dist[j]){
dist[j] = dist[u] + l;
cost[j] = l;
heap.push({dist[j], j});
}
else if (dist[u] + l == dist[j]){
cost[j] = min(cost[j], l);
}
}
}
}
int main(){
int n, m;
scanf("%d%d", &n, &m);
memset(h, -1, sizeof h);
while(m --){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
add(a, b, c), add(b, a, c);
}
memset(st, 0, sizeof st);
memset(dist, 0x3f, sizeof dist);
memset(cost, 0x3f, sizeof cost);
dijkstra(1);
// cout << "-------" << endl;
int ans = 0;
for (int i = 1; i <= n; i ++) ans += cost[i];
cout << ans << endl;
return 0;
}
80分以后改