#include <bits/stdc++.h>
using namespace std;
struct node {
  int u;
  int v;
  int d;
  bool operator<(node b) const { return d < b.d; }
};
node nn[256];
unsigned f[155][5], g[155][5], gg[155][5], tmp[155][5];
int n, m;
void cgf() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= (n >> 5); j++) {
      tmp[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (f[i][j >> 5] & (1 << (j & 31))) {
        for (int k = 0; k <= (n >> 5); k++) {
          tmp[i][k] |= g[j][k];
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= (n >> 5); j++) {
      f[i][j] = tmp[i][j];
    }
  }
}
void cgg() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= (n >> 5); j++) {
      tmp[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (g[i][j >> 5] & (1 << (j & 31))) {
        for (int k = 0; k <= (n >> 5); k++) {
          tmp[i][k] |= g[j][k];
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= (n >> 5); j++) {
      g[i][j] = tmp[i][j];
    }
  }
}
void sol(int d) {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= (n >> 5); j++) {
      g[i][j] = gg[i][j];
    }
  }
  while (d) {
    if (d & 1) {
      cgf();
    }
    cgg();
    d >>= 1;
  }
}
int head[256], last[256], to[256], cnt = 0;
void add(int u, int v) {
  cnt++;
  last[cnt] = head[u];
  head[u] = cnt;
  to[cnt] = v;
}
int d[256];
queue<int> q;
void bfs() {
  for (int i = 1; i <= n; i++) {
    d[i] = -1;
    if (f[1][i >> 5] & (1 << (i & 31))) {
      d[i] = 0;
      q.push(i);
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = last[i]) {
      int v = to[i];
      if (d[v] < 0) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &nn[i].u, &nn[i].v, &nn[i].d);
  }
  sort(nn, nn + m);
  for (int i = 1; i <= n; i++) {
    f[i][i >> 5] |= (1 << (i & 31));
  }
  int nowd = 0;
  for (int i = 0; i < m; i++) {
    bfs();
    if (d[n] >= 0 && nowd + d[n] <= nn[i].d) {
      printf("%d\n", nowd + d[n]);
      return 0;
    }
    sol(nn[i].d - nowd);
    nowd = nn[i].d;
    add(nn[i].u, nn[i].v);
    gg[nn[i].u][nn[i].v >> 5] |= (1 << (nn[i].v & 31));
  }
  bfs();
  if (d[n] >= 0) {
    printf("%d\n", nowd + d[n]);
    return 0;
  }
  printf("Impossible\n");
  return 0;
}
