#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct Edge{
    long long from;
    long long to;
    long long cost;
} a[100010];
long long dist[1000000],n,m;
long long inf = 1000000000001;
bool cmp(Edge x, Edge y)
{
    if( x.from == y.from and x.to == y.to ) return x.cost > y.cost;
    if( x.from == y.from ) return x.to < y.to;
    return x.from < y.from;
}
int main()
{
    scanf("%lld %lld",&n,&m);
    for(int i=0;i<m;i++)
    {
        scanf("%lld %lld %lld",&a[i].from,&a[i].to,&a[i].cost);
    }
    for(int i=1;i<=n;i++)
    {
        dist[i]=inf;
    }
    dist[1]=0;
    for(int ii = 1 ; ii < 4 ; ii++ )
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            long long int  x=a[j].from;
            long long int y=a[j].to;
            long long int z=a[j].cost;

            if((dist[y]>dist[x]+z))
            {
                dist[y]=dist[x]+z;
            }
        }
    }
    if(dist[n]>=inf)
    {
        printf("Impossible");
    }
    else
    {
        printf("%lld",dist[n]);
    }
    return 0;
}
