#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 40);

int main() {
  ll N, M;
  cin >> N >> M;
  vi a(M), b(M), c(M);
  for (ll i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i] -= 1;
    b[i] -= 1;
  }
  vi dist(N, -INF);
  dist[0] = 0;
  vi v;
  for (ll i = 0; i <= 2 * N; i++) {
    for (ll j = 0; j < M; j++) {
      if (dist[a[j]] != -INF) {
        dist[b[j]] = max(dist[b[j]], dist[a[j]] + c[j]);
      }
    }
    v.push_back(dist[N - 1]);
  }

  if (v[v.size() - 1] == v[v.size() - 2]) {
    cout << v[v.size() - 1] << endl;
  } else {
    cout << "inf" << endl;
  }
}