#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
  x = 0;
  long long fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= fh;
}
namespace Network_Flow {
struct Edge {
  long long f, t, w, p, nxt;
  Edge(long long ff, long long tt, long long ww, long long pp, long long nnxt)
      : f(ff), t(tt), w(ww), p(pp), nxt(nnxt) {}
  Edge() {}
} edge[200005];
long long head[10005], etot = 1;
void add_edge(long long f, long long t, long long w, long long p = 0) {
  Edge tmpe(f, t, w, p, head[f]);
  edge[++etot] = tmpe;
  head[f] = etot;
}
void add_nete(long long f, long long t, long long w, long long p = 0) {
  add_edge(f, t, w, p);
  add_edge(t, f, 0, p);
}
long long dep[10005], chd[10005];
queue<long long> q;
void reset() {
  Edge rese(0, 0, 0, 0, 0);
  for (long long i = 1; (i << 1) <= etot; ++i) {
    head[edge[i << 1].f] = head[edge[i << 1].t] = 0;
  }
  for (long long i = 2; i <= etot; ++i) edge[i] = rese;
  etot = 1;
}
bool bfs(long long S, long long T) {
  memset(dep, -1, sizeof(dep));
  dep[S] = 1;
  q.push(S);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (long long i = head[x]; i; i = edge[i].nxt) {
      long long y = edge[i].t, w = edge[i].w;
      if (~dep[y] || !w) continue;
      dep[y] = dep[x] + 1;
      q.push(y);
    }
  }
  return dep[T] != -1;
}
long long dfs(long long x, long long f, long long T) {
  if (x == T) return f;
  long long g = 0;
  for (long long &i = chd[x]; i; i = edge[i].nxt) {
    long long y = edge[i].t;
    if (!edge[i].w || dep[y] != dep[x] + 1) continue;
    long long dd = dfs(y, min(f - g, edge[i].w), T);
    edge[i].w -= dd;
    edge[i ^ 1].w += dd;
    g += dd;
    if (f == g) return g;
  }
  return g;
}
long long Dinic(long long S, long long T) {
  long long ans = 0;
  while (bfs(S, T)) {
    memcpy(chd, head, sizeof(head));
    ans += dfs(S, 0x3f3f3f3f, T);
  }
  return ans;
}
}  // namespace Network_Flow
using Network_Flow::add_nete;
using Network_Flow::Dinic;
long long n, m;
long long sum;
signed main() {
  read(n);
  read(m);
  long long S = n + m + 1, T = S + 1;
  for (long long i = 1, x; i <= n; ++i) {
    read(x);
    add_nete(i + m, T, x);
  }
  for (long long i = 1, u, v, w; i <= m; ++i) {
    read(u);
    read(v);
    read(w);
    add_nete(i, u + m, 0x3f3f3f3f);
    add_nete(i, v + m, 0x3f3f3f3f);
    add_nete(S, i, w);
    sum += w;
  }
  printf("%lld\n", sum - Dinic(S, T));
  return 0;
}
