#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
inline long long bigmod(long long b, long long p, long long m) {
  long long ret = 1, cur = b % m;
  while (p) {
    if (p & 1) ret = (ret * cur) % m;
    cur = (cur * cur) % m;
    p = p >> 1;
  }
  return ret;
}
const long long MAXN = 20010, MAXE = 180006;
long long src, snk, nNode, nEdge;
long long Q[MAXN], fin[MAXN], pro[MAXN], dist[MAXN];
long long flow[MAXE], cap[MAXE], nxt[MAXE], to[MAXE];
inline void init(long long _src, long long _snk, long long _n) {
  src = _src, snk = _snk, nNode = _n, nEdge = 0;
  memset(fin, -1, sizeof(fin));
}
inline void add(long long u, long long v, long long c) {
  to[nEdge] = v, cap[nEdge] = c, flow[nEdge] = 0, nxt[nEdge] = fin[u],
  fin[u] = nEdge++;
  to[nEdge] = u, cap[nEdge] = 0, flow[nEdge] = 0, nxt[nEdge] = fin[v],
  fin[v] = nEdge++;
}
bool bfs() {
  long long st, en, i, u, v;
  memset(dist, -1, sizeof(dist));
  dist[src] = st = en = 0;
  Q[en++] = src;
  while (st < en) {
    u = Q[st++];
    for (i = fin[u]; i >= 0; i = nxt[i]) {
      v = to[i];
      if (flow[i] < cap[i] && dist[v] == -1) {
        dist[v] = dist[u] + 1;
        Q[en++] = v;
      }
    }
  }
  return dist[snk] != -1;
}
long long dfs(long long u, long long fl) {
  if (u == snk) return fl;
  for (long long &e = pro[u], v, df; e >= 0; e = nxt[e]) {
    v = to[e];
    if (flow[e] < cap[e] && dist[v] == dist[u] + 1) {
      df = dfs(v, min(cap[e] - flow[e], fl));
      if (df > 0) {
        flow[e] += df;
        flow[e ^ 1] -= df;
        return df;
      }
    }
  }
  return 0;
}
long long dinitz() {
  long long ret = 0;
  long long df;
  while (bfs()) {
    for (long long i = 1; i <= nNode; i++) pro[i] = fin[i];
    while (true) {
      df = dfs(src, 1e15);
      if (df)
        ret += df;
      else
        break;
    }
  }
  return ret;
}
long long ara[10005];
int main() {
  long long i, x, y, w, n, m;
  scanf("%lld %lld", &n, &m);
  init(1, n + m + 2, n + m + 2);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &ara[i]);
    add(1 + m + i, n + m + 2, ara[i]);
  }
  long long tot = 0;
  for (i = 1; i <= m; i++) {
    scanf("%lld %lld %lld", &x, &y, &w);
    tot += w;
    add(1, 1 + i, w);
    add(1 + i, 1 + m + x, 1e14);
    add(1 + i, 1 + m + y, 1e14);
  }
  long long ret = dinitz();
  cout << tot - ret << endl;
  return 0;
}
