#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    X = (X << 3) + (X << 1) + ch - '0';
    ch = getchar();
  }
  return w ? -X : X;
}
inline void print(long long x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const long long N = 1e6 + 101;
struct Edge {
  long long to, dis, nex;
} edge[N];
long long tot = -1, head[N], cur[N];
long long deep[N], maxflow, n, m, s, t;
long long a[N];
void add(long long from, long long to, long long dis) {
  edge[++tot].nex = head[from];
  edge[tot].to = to;
  edge[tot].dis = dis;
  head[from] = tot;
}
bool bfs(long long s, long long t) {
  for (long long i = s; i <= t; i++) deep[i] = 1e18, cur[i] = head[i];
  deep[s] = 0;
  queue<long long> q;
  q.push(s);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i = head[u]; i != -1; i = edge[i].nex) {
      long long v = edge[i].to;
      if (edge[i].dis && deep[v] == 1e18) {
        deep[v] = deep[u] + 1;
        q.push(v);
      }
    }
  }
  return deep[t] != 1e18;
}
long long dfs(long long now, long long t, long long limit) {
  if (!limit || now == t) return limit;
  long long flow = 0, f;
  for (long long i = cur[now]; i != -1; i = edge[i].nex) {
    long long v = edge[i].to;
    cur[now] = i;
    if (deep[v] == deep[now] + 1 && (f = dfs(v, t, min(limit, edge[i].dis)))) {
      flow += f;
      limit -= f;
      edge[i].dis -= f;
      edge[i ^ 1].dis += f;
      if (!limit) break;
    }
  }
  return flow;
}
void Dinic(long long s, long long t) {
  while (bfs(s, t)) maxflow += dfs(s, t, 1e18);
}
signed main() {
  memset(head, -1, sizeof(head));
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++)
    a[i] = read(), add(s, i, a[i]), add(i, s, 0);
  s = 0;
  t = n + m + 2;
  long long ans = 0;
  for (long long i = 1; i <= m; i++) {
    long long x = read(), y = read(), z = read();
    add(x, n + i, 1e18);
    add(n + i, x, 0);
    add(y, n + i, 1e18);
    add(n + i, y, 0);
    add(n + i, t, z);
    add(t, n + i, 0);
    ans += z;
  }
  Dinic(s, t);
  printf("%lld\n", ans - maxflow);
}
