#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 1000;
const int MAXM = 1000;
const int MAXGN = 2 + MAXN + MAXM;
const int MAXGM = 3 * MAXM + MAXN;
typedef struct MF {
  int n, m;
  int ghead[MAXGN], gnxt[2 * MAXGM], gto[2 * MAXGM];
  long long gcap[2 * MAXGM];
  void init(int _n) {
    n = _n, m = 0;
    for (int i = (0); i < (n); ++i) ghead[i] = -1;
  }
  void addedge(int a, int b, long long c) {
    gnxt[2 * m + 0] = ghead[a], ghead[a] = 2 * m + 0, gto[2 * m + 0] = b,
                 gcap[2 * m + 0] = c;
    gnxt[2 * m + 1] = ghead[b], ghead[b] = 2 * m + 1, gto[2 * m + 1] = a,
                 gcap[2 * m + 1] = 0;
    ++m;
  }
  int d[MAXGN];
  int q[MAXGN], qhead, qtail;
  int cur[MAXGN];
  long long dinic(int s, int t) {
    long long ret = 0;
    int niter = 0;
    while (true) {
      for (int i = (0); i < (n); ++i) d[i] = INT_MAX;
      qhead = qtail = 0;
      d[s] = 0, q[qhead++] = s;
      while (qtail < qhead && d[t] == INT_MAX) {
        int at = q[qtail++];
        for (int x = ghead[at]; x != -1; x = gnxt[x]) {
          int to = gto[x];
          if (gcap[x] == 0 || d[to] != INT_MAX) continue;
          d[to] = d[at] + 1;
          q[qhead++] = to;
        }
      }
      if (d[t] == INT_MAX) return ret;
      for (int i = (0); i < (n); ++i) cur[i] = ghead[i];
      ret += dfs(s, t, LLONG_MAX);
      ++niter;
    }
  }
  long long dfs(int at, int t, long long rem) {
    long long ret = 0;
    if (at == t) return rem;
    if (d[at] >= d[t]) return 0;
    for (; cur[at] != -1; cur[at] = gnxt[cur[at]]) {
      int to = gto[cur[at]];
      long long cap = gcap[cur[at]];
      if (d[to] != d[at] + 1 || cap == 0) continue;
      long long now = dfs(to, t, min(cap, rem));
      rem -= now;
      ret += now;
      if (gcap[cur[at]] != LLONG_MAX) gcap[cur[at]] -= now;
      if (gcap[cur[at] ^ 1] != LLONG_MAX) gcap[cur[at] ^ 1] += now;
      if (rem == 0) return ret;
    }
    return ret;
  }
} MF;
MF g;
int n, m;
int wv[MAXN];
int e[MAXM][2], we[MAXM];
int sid, tid, vid[MAXN], eid[MAXM], nid;
long long solve() {
  nid = 0;
  sid = nid++, tid = nid++;
  for (int i = (0); i < (n); ++i) vid[i] = nid++;
  for (int i = (0); i < (m); ++i) eid[i] = nid++;
  g.init(nid);
  for (int i = (0); i < (m); ++i) g.addedge(sid, eid[i], we[i]);
  for (int i = (0); i < (m); ++i)
    for (int j = (0); j < (2); ++j) g.addedge(eid[i], vid[e[i][j]], LLONG_MAX);
  for (int i = (0); i < (n); ++i) g.addedge(vid[i], tid, wv[i]);
  long long flow = g.dinic(sid, tid);
  long long sum = 0;
  for (int i = (0); i < (m); ++i) sum += we[i];
  return sum - flow;
}
void run() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) scanf("%d", &wv[i]);
  for (int i = (0); i < (m); ++i)
    scanf("%d%d%d", &e[i][0], &e[i][1], &we[i]), --e[i][0], --e[i][1];
  printf("%lld\n", solve());
}
int main() {
  run();
  return 0;
}
