#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MN = 1e4 + 11;
struct edge {
  int u, v, c, f;
  edge(){};
  edge(int u, int v, int c) : u(u), v(v), c(c), f(0){};
};
int s, t, d[MN], giter[MN];
vector<int> g[MN];
int edgemax = 0;
edge edges[4 * MN];
void addedge(int u, int v, int c) {
  edges[edgemax] = edge(u, v, c);
  g[u].push_back(edgemax++);
  edges[edgemax] = edge(v, u, 0);
  g[v].push_back(edgemax++);
}
int bfs(int k) {
  queue<int> q;
  memset(d, -1, MN * sizeof(d[0]));
  d[s] = 0;
  q.push(s);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int e : g[u]) {
      edge &ed = edges[e];
      int v = ed.v;
      if (d[v] == -1 && ed.f + k <= ed.c) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
  return d[t] != -1;
}
long long dfs(int u, int cm, int k) {
  if (!cm) return 0;
  if (u == t) return cm;
  for (int &i = giter[u]; i < (int)g[u].size(); ++i) {
    edge &ed = edges[g[u][i]];
    if (d[ed.v] < d[u] + 1 || ed.c < ed.f + k) continue;
    int d = dfs(ed.v, min(cm, ed.c - ed.f), k);
    if (d) {
      ed.f += d;
      edge &red = edges[g[u][i] ^ 1];
      red.f -= d;
      return d;
    }
  }
  return 0;
}
long long dinic() {
  long long flow = 0;
  for (int i = 0; i >= 0; --i) {
    while (bfs(1 << i)) {
      memset(giter, 0, sizeof(giter));
      while (long long k = dfs(s, 1e9, 1 << i)) {
        flow += k;
      }
    }
  }
  return flow;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  s = 0;
  t = MN - 1;
  int n, m;
  cin >> n >> m;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    long long a;
    cin >> a;
    assert(a <= 1e9);
    addedge(MN / 2 + i, t, a);
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    long long w;
    cin >> u >> v >> w;
    assert(w <= 1e9);
    sum += w;
    addedge(s, i, w);
    addedge(i, MN / 2 + u, 1e15 + 11);
    addedge(i, MN / 2 + v, 1e15 + 11);
  }
  cout << sum - dinic();
}
