#include <bits/stdc++.h> using namespace std; const int maxn = 1e4+10; int n,m,a,b,c,num,cnt; const int INF = 1e9+7; int head[maxn]; typedef pair<int,int>P; priority_queue<P,vector<P>,greater<P> >priq; int vis[maxn]; P dist[maxn]; // edge pos + weight struct edge { int to,weight,nxt; edge(){} edge(int a,int b,int c) {to=a;weight=b;nxt=c;} }e[maxn*20]; void dijkstra() { priq.push(P(0,1)); dist[1] = P(0,0); // watch out! while(!priq.empty()) { P ho = priq.top(); priq.pop(); int now = ho.second; if(vis[now]) continue; vis[now]=1; for(int i=head[now];i;i=e[i].nxt) { int to = e[i].to,weight=e[i].weight; if(!vis[to]){ if(dist[now].second+weight<=dist[to].second){ dist[to] = P(i,dist[now].second+weight); priq.push(P(dist[to].second,to)); } } } } } int main() { cnt=1; memset(head,0,sizeof(head)); memset(vis,0,sizeof(vis)); cin>>n>>m; for(int i=1;i<=n;i++) { dist[i].second=INF; } while(m--) { cin>>a>>b>>c; e[cnt] = edge(b,c,head[a]); head[a] = cnt++; e[cnt] = edge(a,c,head[b]); head[b] = cnt++; } dijkstra(); int tot=0; for(int i=2;i<=n;i++) { int pos=dist[i].first; tot+=e[pos].weight; } cout<<tot<<endl; return 0; }