#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} long long const INF = 1001001001001001001; template struct Edge{ T cost; int from, to; bool operator<(const Edge& right) const{ return this->cost < right.cost; } }; template struct BellmanFord{ bool initialized; int n; int m; vector dist; vector> G; BellmanFord(int _n) : initialized(false), n(_n), m(0), dist(_n, INF) {} void add_edge(int from, int to, T cost){ G.push_back((Edge){cost, from, to}); m++; } void init(int start){ initialized = true; sort(G.begin(), G.end()); dist[start] = 0; rep(time, n + 5){ bool change = false; rep(i, m){ auto e = G[i]; if(dist[e.from] + e.cost < dist[e.to]){ dist[e.to] = dist[e.from] + e.cost; change = true; } } if(!change) break; if(change) if(time > n){ rep(i, n) dist[i] = -INF; return; } } } T get_dist(int from, int to){ if(!initialized) init(from); return dist[to]; } }; int main(){ int n, m; cin >> n >> m; vector a(n); cin >> a; BellmanFord graph(2 * n); rep(i, n) graph.add_edge(i, n + i, -a[i]); rep(i, m){ int u, v, c; cin >> u >> v >> c; u--; v--; graph.add_edge(n + u, v, c); } long long ans = graph.get_dist(0, 2 * n - 1); if(ans == -INF) cout << "inf\n"; else cout << -ans << "\n"; return 0; }