#include //#include using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } #include const long long LINF = 1e18; template class Bellman_ford { public: Bellman_ford(int n, bool longestRoot = false) :n(n), longestRoot(longestRoot) {} void addEdge(int v, int w, T c) { g.push_back({ v, w, c *(longestRoot ? -1 : 1) }); } std::vector solve() { std::vectord(n, LINF); d[0] = 0; // 通常更新パート // n-1回最短経路問題を解くと負閉路がない場合の更新が終わる for (int i = 0; i < n - 1; ++i) { for (int j = 0; j < (int)g.size(); ++j) { if (LINF == d[g[j].from]) continue; if (d[g[j].from] + g[j].cost < d[g[j].to]) d[g[j].to] = d[g[j].from] + g[j].cost; } } // 閉路の伝達パート std::vectorupdate(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < g.size(); ++j) { if (LINF == d[g[j].from]) continue; if (d[g[j].from] + g[j].cost < d[g[j].to]) update[g[j].to] = true; if (update[g[j].from]) update[g[j].to] = true; } } // 負の閉路が存在するなら更新 for (int i = 0; i < n; ++i) { if (update[i])d[i] = -LINF; if (longestRoot) d[i] *= -1; } return d; } private: struct Edge { int from, to; T cost; Edge(int _from, int _to, T _cost) :from(_from), to(_to), cost(_cost) {} }; int n; bool longestRoot; std::vectorg; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vectora(n); rep(i, n)cin >> a[i]; Bellman_ford bf(n, true); rep(i, m) { int x, y, z; cin >> x >> y >> z; x--, y--; bf.addEdge(x, y, a[y] - z); } auto vec = bf.solve(); if (LINF == vec.back())cout << "inf" << endl; else cout << a[0] + vec.back() << endl; return 0; }