#include <bits/stdc++.h>
using namespace std;
long long tot, n, m, ans, head[300101], d[300101];
struct nmb {
  long long start;
  long long end;
  long long edge;
  long long nextx;
} a[300101];
void add(long long x, long long y, long long z) {
  tot++;
  a[tot].start = x;
  a[tot].end = y;
  a[tot].edge = z;
  a[tot].nextx = head[x];
  head[x] = tot;
  return;
}
bool bfs() {
  memset(d, -1, sizeof(d));
  queue<long long> q;
  q.push(0);
  d[0] = 1;
  while (q.size()) {
    long long nown = q.front();
    q.pop();
    for (long long i = head[nown]; i != -1; i = a[i].nextx) {
      long long ee = a[i].end;
      if (a[i].edge > 0 && d[ee] == -1) {
        d[ee] = d[nown] + 1;
        q.push(ee);
      }
    }
  }
  return d[50000] != -1;
}
long long dfs(long long start, long long end, long long nowdat) {
  long long dat = 0;
  if (start == end) return nowdat;
  for (long long i = head[start]; i != -1; i = a[i].nextx) {
    long long ee = a[i].end;
    if (a[i].edge > 0 && d[ee] == d[start] + 1) {
      long long nown = min(nowdat - dat, a[i].edge);
      nown = dfs(ee, end, nown);
      dat += nown;
      a[i].edge -= nown;
      a[i ^ 1].edge += nown;
    }
  }
  if (!dat) d[start] = -2;
  return dat;
}
void dinic() {
  ans = 0;
  while (bfs()) ans += dfs(0, 50000, 1e17);
  return;
}
int main() {
  long long s = 0, t = 50000, sum = 0;
  tot = -1;
  memset(head, -1, sizeof(head));
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    add(i, t, a);
    add(t, i, 0);
  }
  for (long long i = 1; i <= m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    sum += z;
    add(s, i + 1010, z);
    add(i + 1010, s, 0);
    add(i + 1010, x, 1e17);
    add(x, i + 1010, 0);
    add(i + 1010, y, 1e17);
    add(y, i + 1010, 0);
  }
  n = n + m + 2;
  dinic();
  cout << sum - ans << endl;
  return 0;
}
