#include using namespace std; #define int long long signed main() { int n,m; cin >> n >> m; vector>> a(n*2); vector> b(n*2); for(int i = 0; i < n; i++) { int x; cin >> x; a[i].push_back({n+i,-x}); b[n+i].push_back(i); } while(m--) { int x,y,w; cin >> x >> y >> w; x--,y--; a[x+n].push_back({y,w}); b[y].push_back(x+n); } vector vis(n*2,false); vis[n*2-1] = true; deque Q; Q.push_back(n*2-1); while(Q.size() > 0) { int x = Q.front(); Q.pop_front(); int l = b[x].size(); for(int i = 0; i < l; i++) { int y = b[x][i]; if(!vis[y]) { vis[y] = true; Q.push_back(y); } } } vector> dp(n*2+1,vector(n*2,1e18)); dp[0][0] = 0; for(int r = 0; r < n*2; r++) { for(int i = 0; i < n*2; i++) dp[r+1][i] = dp[r][i]; for(int i = 0; i < n*2; i++) { int l = a[i].size(); for(int j = 0; j < l; j++) { int y,w; tie(y,w) = a[i][j]; if(dp[r+1][y] > dp[r][i]+w) { if(r == n*2-1 && vis[y]) { cout << "inf" << endl; return 0; } dp[r+1][y] = min(dp[r+1][y],dp[r][i]+w); } } } } cout << dp[n*2][n*2-1]*-1 << endl; }