#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  int x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(int a) {
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(int a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
const int N = 155;
struct matrix {
  bitset<N> a[N];
} sum, zs, ans;
int n, m, sss;
pair<int, pair<int, int> > a[N];
matrix operator+(matrix &x, matrix &y) {
  matrix ans;
  for (int i = 0; i < n; i++) ans.a[i] = x.a[i];
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++)
      if (x.a[i][k]) {
        ans.a[i] |= y.a[k];
      }
  }
  return ans;
}
matrix add(matrix ans, matrix zs, int k) {
  for (; k; k >>= 1) {
    if (k & 1) ans = ans + zs;
    zs = zs + zs;
  }
  return ans;
}
matrix operator*(matrix &x, matrix &y) {
  matrix ans;
  for (int i = 0; i < n; i++) ans.a[i].reset();
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++)
      if (x.a[i][k]) {
        ans.a[i] |= y.a[k];
      }
  }
  return ans;
}
matrix mul(matrix ans, matrix zs, int k) {
  for (; k; k >>= 1) {
    if (k & 1) ans = ans * zs;
    zs = zs * zs;
  }
  return ans;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int u = read() - 1, v = read() - 1;
    a[i].second = make_pair(u, v);
    a[i].first = read();
  }
  sort(&a[1], &a[m + 1]);
  a[m + 1].first = a[m].first + 1e9;
  if (a[1].first) {
    puts("Impossible");
    return 0;
  }
  ans.a[0][0] = sum.a[0][0] = 1;
  for (int i = 1; i <= m; i++)
    if (a[i].first != a[i + 1].first) {
      for (int j = 0; j < n; j++) zs.a[i].reset();
      for (int j = 1; j <= i; j++)
        zs.a[a[j].second.first][a[j].second.second] = 1;
      matrix t = add(ans, zs, a[i + 1].first - a[i].first);
      if (t.a[0][n - 1]) {
        int l = a[i].first + 1, r = a[i + 1].first;
        while (l < r) {
          int mid = ((long long)l + r) >> 1;
          if (add(ans, zs, mid - a[i].first).a[0][n - 1])
            r = mid;
          else
            l = mid + 1;
        }
        writeln(l);
        return 0;
      }
      sum = t;
      ans = mul(ans, zs, a[i + 1].first - a[i].first);
    }
  puts("Impossible");
}
