#include <bits/stdc++.h>
using namespace std;
const int size = 1 << 20, mod = 998244353, inf = 2e9;
template <class o>
void qr(o &x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr1(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar('\n');
}
int n, m;
namespace Flow {
const int N = 2e3 + 10, M = N * 5;
const long long INF = 1e15;
int d[N], q[N], l, r, st, ed;
struct edge {
  int y, next;
  long long c;
} a[M];
int len = 1, last[N], cur[N];
void clear() {
  len = 1;
  memset(last, 0, sizeof last);
}
void ins(int x, int y, long long c) {
  a[++len] = (edge){y, last[x], c};
  last[x] = len;
}
void add(int x, int y, long long c) {
  ins(x, y, c);
  ins(y, x, 0);
}
bool bfs() {
  q[l = r = 1] = st;
  memset(d, 0, sizeof d);
  d[st] = 1;
  for (int x = st; l <= r; x = q[++l])
    for (int k = last[x], y; k; k = a[k].next)
      if (a[k].c && !d[y = a[k].y]) d[q[++r] = y] = d[x] + 1;
  return d[ed];
}
long long dfs(int x, long long f) {
  if (x == ed) return f;
  long long s = 0, t;
  for (int &k = cur[x], y; k; k = a[k].next) {
    y = a[k].y;
    long long z = min(f - s, a[k].c);
    if (z && d[y] == d[x] + 1) {
      s += t = dfs(y, z);
      a[k].c -= t;
      a[k ^ 1].c += t;
      if (s == f) return f;
    }
  }
  if (!s) d[x] = 0;
  return s;
}
long long dinic() {
  long long ans = 0;
  while (bfs()) {
    memcpy(cur, last, sizeof cur);
    ans += dfs(st, INF);
  }
  return ans;
}
}  // namespace Flow
using namespace Flow;
void solve() {
  qr(n);
  qr(m);
  st = n + m + 1;
  ed = st + 1;
  long long ans = 0;
  for (int i = 1, x; i <= n; i++) qr(x), add(st, i, x);
  for (int i = n + 1, x, y, z; i <= n + m; i++) {
    qr(x);
    qr(y);
    qr(z);
    ans += z;
    add(x, i, inf);
    add(y, i, inf);
    add(i, ed, z);
  }
  pr2(ans - dinic());
}
int main() {
  solve();
  return 0;
}
