#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& os, vector<bitset<150>>& v) {
  for (int i = 0; i < v.size(); i++) {
    os << v[i] << endl;
  }
  os << endl;
  return os;
}
vector<bitset<150>> transpose(vector<bitset<150>>& A, int n) {
  vector<bitset<150>> ret(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ret[j][i] = A[i][j];
    }
  }
  return ret;
}
vector<bitset<150>> mult(vector<bitset<150>> A, vector<bitset<150>> B, int n) {
  vector<bitset<150>> tB = transpose(B, n);
  vector<bitset<150>> C(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      C[i][j] = (A[i] & tB[j]).count() > 0;
    }
  }
  return C;
}
vector<bitset<150>> pow(vector<bitset<150>> A, long long k, int n) {
  vector<bitset<150>> ret(n);
  for (int i = 0; i < n; i++) {
    ret[i][i] = 1;
  }
  while (k) {
    if (k & 1) ret = mult(ret, A, n);
    A = mult(A, A, n);
    k >>= 1;
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m), d_(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> d_[i];
    a[i]--;
    b[i]--;
  }
  vector<pair<long long, int>> e(m);
  for (int i = 0; i < m; i++) {
    e[i] = {d_[i], i};
  }
  sort(e.begin(), e.end());
  e.push_back({1e12, -1});
  vector<bitset<150>> v(n);
  for (int i = 0; i < n; i++) {
    v[i][i] = 1;
  }
  vector<bitset<150>> r(n);
  r[n - 1][n - 1] = 1;
  long long d = 0;
  for (int i = 0; i < m; i++) {
    bool update = false;
    while (i <= m && e[i].first == d) {
      int j = e[i].second;
      if (j < 0) break;
      r[a[j]][b[j]] = 1;
      i++;
      update = true;
    }
    if (!update) break;
    i--;
    long long next_d = e[i + 1].first;
    auto v_ = mult(v, pow(r, next_d - d, n), n);
    if (v_[0][n - 1]) {
      long long lb = d;
      long long ub = next_d;
      while (ub - lb > 1) {
        long long mid = (lb + ub) / 2;
        auto tmp = mult(v, pow(r, mid - d, n), n);
        if (tmp[0][n - 1]) {
          ub = mid;
        } else {
          lb = mid;
        }
      }
      cout << ub << endl;
      return 0;
    }
    v = v_;
    d = next_d;
  }
  cout << "Impossible" << endl;
  return 0;
}
