#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
typedef bitset<150> arr[151];
int n, ans;
void copy(arr &a, arr b) {
  for (int i = 0; i < n; i++) a[i] = b[i];
}
void mul(arr &a, arr b) {
  arr c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j]) c[i] |= b[j];
  copy(a, c);
}
void mul1(bitset<150> &c, arr b) {
  bitset<150> a;
  for (int i = 0; i < n; i++)
    if (c[i]) a |= b[i];
  c = a;
}
bool check(bitset<150> &c, arr &b) {
  static int dp[151];
  for (int i = 0; i < n; i++) dp[i] = -1;
  queue<int> q;
  for (int i = 0; i < n; i++)
    if (c.test(i)) {
      dp[i] = 0;
      q.push(i);
    }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < n; i++)
      if (b[u].test(i) && dp[i] == -1) {
        dp[i] = dp[u] + 1;
        q.push(i);
      }
  }
  if (dp[n - 1] != -1) {
    ans += dp[n - 1];
    c.set(n - 1);
    return 1;
  }
  return 0;
}
struct edge {
  int u, v, w;
  bool operator<(const edge &a) const { return w < a.w; }
} e[200];
vector<pair<int, int> > g[200];
int main() {
  int T, i, j, k, m;
  scanf("%d%d", &n, &m);
  ans = 0;
  for (i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d%d", &u, &v, &k);
    u--, v--;
    e[i] = (edge){u, v, k};
    g[u].push_back(make_pair(v, k));
  }
  if (n == 1) {
    printf("1\n1\n");
    return 0;
  }
  sort(e, e + m);
  if (e[0].w) {
    puts("Impossible");
    return 0;
  }
  int d[151];
  for (i = 0; i < n; i++) d[i] = -1;
  d[0] = 0;
  priority_queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    int u = q.top().second, v = -q.top().first;
    q.pop();
    if (d[u] != v) continue;
    for (i = 0; i < g[u].size(); i++) {
      j = g[u][i].first;
      k = g[u][i].second;
      if (d[j] == -1 || d[j] > max(d[u], k)) {
        d[j] = max(d[u], k);
        q.push(make_pair(-d[j], j));
      }
    }
  }
  if (d[n - 1] == -1) {
    puts("Impossible");
    return 0;
  }
  int D = d[n - 1];
  arr b;
  bitset<150> c;
  c.set(0);
  for (i = 0; i < m; i = j) {
    j = i;
    while (j < m && e[j].w == e[i].w) {
      b[e[j].u].set(e[j].v);
      j++;
    }
    if (e[i].w == D) break;
    if (j < m) {
      int len = e[j].w - e[i].w;
      arr bb;
      copy(bb, b);
      while (len) {
        if (len & 1) mul1(c, bb);
        mul(bb, bb);
        len >>= 1;
      }
      ans = e[j].w;
    }
  }
  check(c, b);
  if (!c[n - 1]) {
    puts("Impossible");
  } else {
    printf("%d\n", ans);
  }
  return 0;
}
