#include <bits/stdc++.h>
using namespace std;
const long long N = 151, M = 33, INF = 1e10;
struct mat {
  bitset<N> r[N], c[N];
  mat() {
    for (long long i = 0; i < N; i++) {
      r[i].reset();
      c[i].reset();
    }
  }
  void set(long long x, long long y) {
    r[x].set(y);
    c[y].set(x);
  }
  bool get(long long x, long long y) { return r[x][y]; }
} I;
struct ed {
  long long v, u, d;
  ed() : v(-1), u(-1), d(INF) {}
  ed(long long v, long long u, long long d) : v(v), u(u), d(d) {}
};
long long n, m, len[N];
ed e[N];
mat mats[N];
mat mul(const mat &a, const mat &b) {
  mat ret = mat();
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++)
      if ((a.r[i] & b.c[j]).any()) ret.set(i, j);
  return ret;
}
mat bp(const mat &a, long long b) {
  if (b == 0) return I;
  mat x = bp(a, b / 2);
  x = mul(x, x);
  return b & 1 ? mul(x, a) : x;
}
inline bool cmp(const ed &a, const ed &b) { return a.d < b.d; }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  I = mat();
  for (long long i = 0; i < n; i++) I.set(i, i);
  for (long long i = 0; i < m; i++) {
    long long a, b, d;
    cin >> a >> b >> d;
    a--;
    b--;
    e[i] = ed(a, b, d);
  }
  sort(e, e + m, cmp);
  e[m++] = ed();
  long long sz = 0;
  mat cur = mat();
  cur.set(n - 1, n - 1);
  for (long long i = 0; i < m; i++) {
    if (i == 0 && e[i].d > 0) {
      cout << "Impossible\n";
      return 0;
    }
    if (i && e[i].d > e[i - 1].d) {
      mats[sz] = cur;
      len[sz++] = e[i].d - e[i - 1].d;
    }
    if (i != m - 1) cur.set(e[i].v, e[i].u);
  }
  cur = I;
  long long ans = 0;
  for (long long i = 0; i < sz; i++) {
    mat now = mul(cur, bp(mats[i], len[i]));
    if (now.get(0, n - 1)) {
      for (long long bit = M; bit >= 0; bit--) {
        mat tmp = mul(cur, bp(mats[i], (1 << bit)));
        if (!tmp.get(0, n - 1)) {
          cur = tmp;
          ans += (1 << bit);
        }
      }
      cout << ans + 1 << "\n";
      return 0;
    }
    cur = now;
    ans += len[i];
  }
  cout << "Impossible\n";
  return 0;
}
