#include <bits/stdc++.h>
using namespace std;
const int N = 155;
bitset<N> dp[33][N];
int n, m;
void prop(int lvl, int i, int j) {
  dp[lvl][i][j] = 1;
  if (lvl > 30) return;
  for (int k = 0; k < n; k++) {
    if (dp[lvl][k][i] and !dp[lvl + 1][k][j]) {
      prop(lvl + 1, k, j);
    }
    if (dp[lvl][j][k] and !dp[lvl + 1][i][k]) {
      prop(lvl + 1, i, k);
    }
  }
}
int a[N], b[N], d[N];
int dt[N];
vector<int> g[N];
int bfs(const bitset<N> &me, int starting_dist) {
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (me[i]) {
      dt[i] = starting_dist;
      q.push(i);
    } else {
      dt[i] = -1;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : g[u])
      if (dt[v] == -1) {
        dt[v] = dt[u] + 1;
        q.push(v);
      }
  }
  return dt[n - 1] == -1 ? INT_MAX : dt[n - 1];
}
int main() {
  scanf("%d %d", &n, &m);
  vector<int> ids;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", a + i, b + i, d + i);
    a[i]--, b[i]--;
    ids.push_back(i);
  }
  sort(ids.begin(), ids.end(), [](int i, int j) { return d[i] < d[j]; });
  int ans = INT_MAX;
  int prev = 0;
  bitset<N> me;
  me[0] = 1;
  for (int i : ids) {
    int tmp = d[i] - prev;
    for (int j = 30; j >= 0; j--)
      if (tmp >> j & 1) {
        bitset<N> nmask;
        for (int u = 0; u < n; u++)
          if (me[u]) {
            nmask |= dp[j][u];
          }
        me = nmask;
      }
    g[a[i]].push_back(b[i]);
    ans = min(ans, bfs(me, d[i]));
    if (!dp[0][a[i]][b[i]]) {
      prop(0, a[i], b[i]);
    }
    prev = d[i];
  }
  if (ans == INT_MAX) {
    printf("Impossible\n");
  } else {
    printf("%d\n", ans);
  }
}
