#include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#include<iostream>
#include<list>
#include<stack>
#include<deque>
#include<cstring>
using namespace std;
struct node
{
    int to;
    int w;
    int nex;
    bool operator > (const node temp) const
    {
        return w>temp.w;
    }
}a[10005];
int first[10005];
int dis[10005];
int vis[10005];
priority_queue< node, vector<node> ,greater<node> > q;
int main()
{
    //freopen("in.txt","r",stdin);
    int tmp1,tmp2,tmp3;
    memset(a,-1,sizeof(0));
    memset(first,-1,sizeof(first));
    memset(vis,-1,sizeof(vis));
    memset(dis,0x3f,sizeof(dis));
    int t,n;
    scanf("%d%d",&t,&n);
    int cnt=1;
    for(int i=1;i<=t;i++)
    {
        scanf("%d%d%d",&tmp1,&tmp2,&tmp3);
        a[cnt].nex=first[tmp1];
        a[cnt].to=tmp2;
        a[cnt].w=tmp3;
        first[tmp1]=cnt;
        cnt++;
        a[cnt].nex=first[tmp2];
        a[cnt].to=tmp1;
        a[cnt].w=tmp3;
        first[tmp2]=cnt;
        cnt++;
    }
    dis[1]=0;
    node temp;
    temp.to=1;
    temp.w=0;
    temp.nex=0;
    q.push(temp);
    while(q.size())
    {
        //while q.sizeof()
        node temp2;
        temp=q.top();
        q.pop();
        //cout<<temp.to<<endl;
        if(vis[temp.to]==1) continue;
        vis[temp.to]=1;
        for(int i=first[temp.to];i!=-1;i=a[i].nex)
        {
            //cout<<a[i].to<<endl;
            if(dis[a[i].to]>dis[temp.to]+a[i].w)
            {
                dis[a[i].to]=dis[temp.to]+a[i].w;
                temp2.w=dis[a[i].to];
                temp2.to=a[i].to;
                q.push(temp2);
            }
        }
       // cout<<endl;
    }
    printf("%d\n",dis[n]);
}