#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=1005;
bool vis[maxn];
int dis[maxn],N;
struct Node{
int t, w;
bool operator<(const Node n) const {
return w>n.w;
}
};
vector<Node> adj[maxn];
int dijkstra(){
priority_queue<Node> q;
q.push(Node{1,0});
memset(vis,0,sizeof(vis));
int cnt=0;
while(!q.empty()){
Node n=q.top(),tmp;
q.pop();
if(vis[n.t]) continue;
vis[n.t]=true;
dis[n.t]=n.w;
if(++cnt==N) break;
for(int i=0;i<adj[n.t].size();i++){
tmp=adj[n.t][i];
q.push((Node){tmp.t,n.w+tmp.w});
}
}
return dis[N];
}
int main(){
int T,s,t,w;
scanf("%d%d",&T,&N);
while(T--){
scanf("%d%d%d",&s,&t,&w);
adj[s].push_back((Node){t,w});
adj[t].push_back((Node){s,w});
}
printf("%d\n",dijkstra());
}