#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].push_back({b,A[b]-c}); } vector dp(N,-infl); dp[0]=A[0]; rep(i,2*N){ vector dp2; dp2=dp; rep(j,N){ for (auto e:G[j]){ if (dp[j]==-infl) continue; if (i>=N && e.first==N-1){ if (dp2[e.first]