#include #include using mint = atcoder::modint998244353; // using mint = atcoder::modint1000000007; using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < n; i++) using ll = long long; set abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; const int inf =1e9; const ll infl = 4e18; template bool chmax(T &a, const T& b) {if (a < b) {a = b; return true;}return false;} template bool chmin(T &a, const T& b) {if (a > b) {a = b; return true;}return false;} int main(){ int N,M; cin >> N >> M; vector A(N);rep(i,N) cin >> A[i]; vector>> G(N); rep(i,M){ int a,b; ll c; cin >> a >> b >> c; a--;b--; G[a].emplace_back(b,A[b]-c); } vector dist(N,-infl); dist[0]=A[0]; rep(i,N-1){ rep(j,N){ if(dist[j]==-infl) continue; for(auto p:G[j]){ if(dist[p.first]