#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int dis[35];
int visit[35];
int SSSP[35][35];
void dijkstra(int x,int n)
{
   int pos;
   int minn;
   for(int i=1;i<=n;i++)
   {
      dis[i]=SSSP[1][i];
   }
   visit[x]=1;
   dis[x]=0;
   for(int i=1;i<=n;i++)
   {
        minn=INF;
        pos=0;
        for(int j=1;j<=n;j++)
        {
           if(!visit[j]&&dis[j]<minn)
           {
              pos=j;
              minn=dis[j];
           }

        }
        if(pos==0) break;
        else
        {
            visit[pos]=1;
            for(int j=1;j<=n;j++)
            {
               if(!visit[j]&& dis[pos]+SSSP[pos][j]<dis[j])
                 dis[j]=dis[pos]+SSSP[pos][j];
            }
        }

   }
}
int main()
{
   while(1)
   {
      int n,m;   cin>>n>>m;
      if(n==0&&m==0) break;  int zzzzz=0;


      memset(visit,0,sizeof(visit));
      memset(dis,0,sizeof(dis));
      memset(SSSP,0,sizeof(SSSP));

      for(int i=1;i<=n;i++)
      {
         for(int j=1;j<=n;j++)
           SSSP[i][j]=INF;
      }
      int a[1005];
      int b[1005];
      int t[1005];
      for(int i=1;i<=m;i++)
      {
          cin>>a[i]>>b[i]>>t[i];
          SSSP[a[i]][b[i]]=t[i];
          SSSP[b[i]][a[i]]=t[i];
      }
      dijkstra(1,n);   //cout<<"*****"<<dis[n]<<"*******"<<zzzzz<<"******"<<endl;
      if(dis[n]==INF)
      {
        zzzzz=1;
      }
      int maxn=dis[n];

      for(int i=2;i<n;i++)
      {
         //  qu dian chong ding yi
         if(zzzzz==1) break;
         for(int j=1;j<=n;j++)
         {
             for(int j1=1;j1<=n;j1++)
                SSSP[j][j1]=INF;
         }
         for(int j=1;j<=m;j++)
         {
              SSSP[a[j]][b[j]]=t[j];
             SSSP[b[j]][a[j]]=t[j];
             if(a[j]==i||b[j]==i)
             {
               SSSP[a[j]][b[j]]=INF;
               SSSP[b[j]][a[j]]=INF;
             }
         }
         //  chong ding yi   visit[]   dis

         memset(visit,0,sizeof(visit));
         memset(dis,0,sizeof(dis));


         dijkstra(1,n);  // cout<<"*****"<<dis[n]<<"*******"<<zzzzz<<"******"<<endl;
         if(dis[n]==INF)
         {
            zzzzz=1;
         }
         if(dis[n]>maxn) maxn=dis[n];
      }
      if(zzzzz==0)
      cout<<maxn<<endl;
      if(zzzzz==1)
      cout<<"Inf"<<endl;
   }
}