#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const long long INF = 1e18;
int n, m;
int T;
int et, fir[MAXN], to[MAXN], ne[MAXN], cur[MAXN];
long long cap[MAXN];
int dis[MAXN];
void link(int u, int v, long long x) {
  to[++et] = v, ne[et] = fir[u], fir[u] = et;
  to[++et] = u, ne[et] = fir[v], fir[v] = et;
  cap[et - 1] = x, cap[et] = 0;
}
bool bfs() {
  static int que[MAXN];
  int head = 0, tail = 0;
  for (int i = 0; i <= T; i++) dis[i] = 0;
  que[tail++] = 0, dis[0] = 1;
  while (head != tail) {
    int o = que[head++];
    for (int i = fir[o]; i; i = ne[i])
      if (cap[i] && !dis[to[i]]) {
        dis[to[i]] = dis[o] + 1;
        que[tail++] = to[i];
      }
  }
  return dis[T] != 0;
}
long long dfs(int o, long long _min) {
  if (o == T) return _min;
  long long res = 0;
  for (int &i = cur[o]; i; i = ne[i])
    if (cap[i] && dis[to[i]] == dis[o] + 1) {
      long long x = dfs(to[i], min(_min - res, cap[i]));
      cap[i] -= x, cap[i ^ 1] += x;
      res += x;
      if (res == _min) return res;
    }
  if (!res) dis[o] = -1;
  return res;
}
int main() {
  cin >> n >> m;
  et = 1;
  T = n + m + 1;
  for (int i = 1, x; i <= n; i++) cin >> x, link(0, i, x);
  long long ans = 0;
  for (int i = 1, x, y, z; i <= m; i++) {
    cin >> x >> y >> z;
    link(x, i + n, INF), link(y, i + n, INF);
    link(i + n, T, z);
    ans += z;
  }
  while (bfs()) {
    for (int i = 0; i <= T; i++) cur[i] = fir[i];
    ans -= dfs(0, INF);
  }
  cout << ans << endl;
  return 0;
}
