#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 - 48 + ch;
  return x;
}
const int N = 1005;
struct edge {
  int to, next;
  long long f;
} e[N * 8];
int head[N * 2], tot = 1;
void add(int x, int y, long long v) {
  e[++tot] = (edge){y, head[x], v};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], 0};
  head[y] = tot;
}
int dis[N * 2], q[N * 2];
int S, T, n, m;
bool bfs() {
  for (int i = (int)(1); i <= (int)(T); i++) dis[i] = -1;
  int t = 1;
  dis[q[1] = S] = 0;
  for (int h = (int)(1); h <= (int)(t); h++)
    for (int i = head[q[h]]; i; i = e[i].next)
      if (dis[e[i].to] == -1 && e[i].f) {
        dis[q[++t] = e[i].to] = dis[q[h]] + 1;
        if (e[i].to == T) return 1;
      }
  return 0;
}
long long dfs(int x, long long flow) {
  if (x == T) return flow;
  long long k, rest = flow;
  for (int i = head[x]; i && rest; i = e[i].next)
    if (dis[e[i].to] == dis[x] + 1 && e[i].f) {
      k = dfs(e[i].to, min(rest, e[i].f));
      e[i].f -= k;
      e[i ^ 1].f += k;
      rest -= k;
    }
  if (rest) dis[x] = -1;
  return flow - rest;
}
long long ans;
int main() {
  scanf("%d%d", &n, &m);
  S = n + m + 1;
  T = S + 1;
  for (int i = (int)(1); i <= (int)(n); i++) add(i, T, read());
  for (int i = (int)(1); i <= (int)(m); i++) {
    add(i + n, read(), (1ll << 60));
    add(i + n, read(), (1ll << 60));
    int v = read();
    add(S, i + n, v);
    ans += v;
  }
  while (bfs()) ans -= dfs(S, (1ll << 60));
  printf("%lld\n", ans);
}
