#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)9e18;
const long long N = 10000;
long long n, m, dep[N * 2], S, T, a[N];
struct edge {
  long long v, f;
  edge *next, *rev;
} pool[N * 2], *head[N], *cur = pool;
inline void addedge(long long u, long long v, long long f) {
  edge *p = cur++, *q = cur++;
  p->v = v, p->f = f, p->next = head[u], head[u] = p;
  p->rev = q;
  q->v = u, q->f = 0, q->next = head[v], head[v] = q;
  q->rev = p;
}
inline bool bfs() {
  memset(dep, 0, sizeof(dep));
  queue<long long> Q;
  Q.push(S), dep[S] = 1;
  while (!Q.empty()) {
    long long u = Q.front();
    Q.pop();
    for (edge *p = head[u]; p; p = p->next) {
      long long v = p->v;
      if (!dep[v] && p->f) {
        dep[v] = dep[u] + 1;
        if (v == T) return 1;
        Q.push(v);
      }
    }
  }
  return 0;
}
inline long long dfs(long long u, long long lim) {
  if (u == T) return lim;
  long long ret = 0, v;
  for (edge *p = head[u]; p && lim; p = p->next) {
    if (p->f && dep[v = p->v] == dep[u] + 1) {
      long long tmp = dfs(v, min(lim, p->f));
      if (tmp) p->f -= tmp, p->rev->f += tmp, ret += tmp, lim -= tmp;
    }
  }
  if (!ret) dep[u] = -1;
  return ret;
}
inline long long dinic() {
  long long ret = 0;
  while (bfs()) ret += dfs(S, INF);
  return ret;
}
signed main() {
  scanf("%lld %lld", &n, &m);
  S = 0, T = n + m + 1;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    addedge(S, i, a[i]);
  }
  long long ans = 0;
  for (long long i = 1; i <= m; i++) {
    long long u, v, w;
    scanf("%lld %lld %lld", &u, &v, &w);
    addedge(u, i + n, INF);
    addedge(v, i + n, INF);
    addedge(i + n, T, w);
    ans += w;
  }
  printf("%lld\n", ans - dinic());
  return 0;
}
