#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1, 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

class bellman_ford {
  private:
    struct edge {
        int from, to;
        long long cost;
    };
    const long long INF = 4'000'000'000'000'000'000;
    int V;
    vector<edge> E;
    vector<long long> dist;

  public:
    bellman_ford(int vertex) {
        V = vertex;
        dist.resize(V, INF);
    }
    void directed_update(int x, int y, long long cost) {
        E.push_back({x, y, cost});
    }
    void undirected_update(int x, int y, long long cost) {
        E.push_back({x, y, cost});
        E.push_back({y, x, cost});
    }
    bool calc(int start) {
        dist[start] = 0;
        for (int i = 0; i < 2 * V; i++) {
            for (int j = 0; j < E.size(); j++) {
                auto e  = E[j];
                int tmp = dist[V - 1];
                if (dist[e.from] != INF && dist[e.from] + e.cost < dist[e.to]) {
                    dist[e.to] = dist[e.from] + e.cost;
                    if (V - 1 <= i && dist[V - 1] < tmp)
                        return false;
                }
            }
        }
        return true;
    }

    pair<long long, bool> min_dist(int to) {
        pair<long long, bool> ans;
        if (dist[to] == INF)
            ans = {-1, false};
        else
            ans = {dist[to], true};
        return ans;
    }
    bool is_all_negative() {
        vector<long long> d(V);
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < E.size(); j++) {
                auto e = E[j];
                if (d[e.from] + e.cost < d[e.to]) {
                    d[e.to] = d[e.from] + e.cost;
                    if (i == V - 1)
                        return true;
                }
            }
        }
        return false;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    auto bf = bellman_ford(N);
    REP(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        bf.directed_update(a, b, -c);
    }
    if (!bf.calc(0)) {
        print("inf");
    } else {
        print(-bf.min_dist(N - 1).first);
    }

    return 0;
}

Measured memory_bytes: 384