#include <bits/stdc++.h>
using namespace std;
const int MAXN = 155;
const int MAXM = 155;
const int INF = 2e9 + 10;
int n, m;
struct edge {
  int u, v, d;
  bool operator<(const edge& o) const { return d < o.d; }
} e[MAXM];
struct mat {
  bitset<MAXN> ele[MAXN];
  mat() {
    for (int i = 1; i <= n; i++) ele[i].reset();
  }
  inline void unit() {
    for (int i = 1; i <= n; i++) ele[i].reset(), ele[i].set(i);
  }
  inline friend mat operator*(mat x, mat y) {
    mat res;
    for (int k = 1; k <= n; k++)
      for (int i = 1; i <= n; i++)
        if (x.ele[i][k]) res.ele[i] |= y.ele[k];
    return res;
  }
  inline friend mat pw(mat x, int p) {
    mat res;
    res.unit();
    for (; p; p >>= 1, x = x * x)
      if (p & 1) res = res * x;
    return res;
  }
} g, a;
long long dis[MAXN];
queue<int> q;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].d);
  sort(e + 1, e + m + 1);
  long long ans = INF;
  a.unit();
  for (int i = 1; i <= m; i++) {
    if (e[i].d >= ans) break;
    a = a * pw(g, e[i].d - e[i - 1].d);
    g.ele[e[i].u].set(e[i].v);
    while (!q.empty()) q.pop();
    for (int i = 1; i <= n; i++)
      if (a.ele[1][i])
        dis[i] = 0, q.push(i);
      else
        dis[i] = INF;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 1; i <= n; i++) {
        if (g.ele[u][i] && dis[i] == INF) {
          dis[i] = dis[u] + 1;
          q.push(i);
        }
      }
    }
    ans = min(ans, e[i].d + dis[n]);
  }
  if (ans == INF)
    puts("Impossible");
  else
    printf("%lld\n", ans);
  return 0;
}
