#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 100;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 2010;
struct Dinic {
  struct Edge {
    int from, to;
    long long flow, cap;
  };
  vector<Edge> edge;
  vector<int> g[N];
  int ne = 0;
  int lvl[N], vis[N], pass;
  int qu[N], px[N], qt;
  long long run(int s, int sink, long long minE) {
    if (s == sink) return minE;
    long long ans = 0;
    for (; px[s] < (int)g[s].size(); px[s]++) {
      int e = g[s][px[s]];
      auto &v = edge[e], &rev = edge[e ^ 1];
      if (lvl[v.to] != lvl[s] + 1 || v.flow >= v.cap) continue;
      long long tmp = run(v.to, sink, min(minE, v.cap - v.flow));
      v.flow += tmp, rev.flow -= tmp;
      ans += tmp, minE -= tmp;
      if (minE == 0) break;
    }
    return ans;
  }
  bool bfs(int source, int sink) {
    qt = 0;
    qu[qt++] = source;
    lvl[source] = 1;
    vis[source] = ++pass;
    for (int i = 0; i < qt; i++) {
      int u = qu[i];
      px[u] = 0;
      if (u == sink) return true;
      for (auto& ed : g[u]) {
        auto v = edge[ed];
        if (v.flow >= v.cap || vis[v.to] == pass) continue;
        vis[v.to] = pass;
        lvl[v.to] = lvl[u] + 1;
        qu[qt++] = v.to;
      }
    }
    return false;
  }
  long long flow(int source, int sink) {
    reset_flow();
    long long ans = 0;
    while (bfs(source, sink)) ans += run(source, sink, LLINF);
    return ans;
  }
  void addEdge(int u, int v, long long c, long long rc) {
    Edge e = {u, v, 0, c};
    edge.push_back(e);
    g[u].push_back(ne++);
    e = {v, u, 0, rc};
    edge.push_back(e);
    g[v].push_back(ne++);
  }
  void reset_flow() {
    for (int i = 0; i < ne; i++) edge[i].flow = 0;
    memset(lvl, 0, sizeof(lvl));
    memset(vis, 0, sizeof(vis));
    memset(qu, 0, sizeof(qu));
    memset(px, 0, sizeof(px));
    qt = 0;
    pass = 0;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  Dinic dnc;
  int source = 2005, sink = 2006;
  int n, m, v, u, w;
  cin >> n >> m;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dnc.addEdge(i, sink, a[i], 0);
  }
  for (int i = 0; i < m; i++) {
    cin >> v >> u >> w;
    u--;
    v--;
    sum += w;
    dnc.addEdge(source, i + n, w, 0);
    dnc.addEdge(i + n, u, LLINF, 0);
    dnc.addEdge(i + n, v, LLINF, 0);
  }
  cout << sum - dnc.flow(source, sink) << '\n';
  return 0;
}
