#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int N = 1e7 + 5;
class Dinic {
 private:
  const static ll INF = 8 * (ll)1e18;
  struct Edge {
    const int t;
    ll a;
    Edge(int tar, ll cap = INF) : t(tar), a(cap) {}
  };
  vector<Edge> edges;
  vector<vector<int>> conns;
  vector<int> dist, act_ind;
  ll push(int ei, ll v) {
    edges[ei].a -= v;
    edges[ei ^ 1].a += v;
    return v;
  }
  void calcDists(int sink) {
    for (int& v : dist) v = -1;
    dist[sink] = 0;
    vector<int> que = {sink};
    for (int j = 0; j < que.size(); ++j) {
      for (auto ei : conns[que[j]]) {
        int t = edges[ei].t;
        if (edges[ei ^ 1].a > 0 && dist[t] == -1) {
          dist[t] = dist[que[j]] + 1;
          que.push_back(t);
        }
      }
    }
  }
  ll dfsFlow(int i, int sink, ll cap) {
    if (i == sink) return 0;
    for (int& j = act_ind[i]; j < conns[i].size(); ++j) {
      int ei = conns[i][j];
      int t = edges[ei].t;
      if (dist[t] != dist[i] - 1 || edges[ei].a == 0) continue;
      ll subcap = min(cap, edges[ei].a);
      cap -= push(ei, subcap - dfsFlow(t, sink, subcap));
      if (!cap) return 0;
    }
    return cap;
  }

 public:
  Dinic(int n) : conns(n), dist(n), act_ind(n) {}
  int addEdge(int s, int t, ll c = INF, bool dir = 1) {
    4;
    int i = edges.size() / 2;
    edges.emplace_back(t, c);
    edges.emplace_back(s, dir ? 0 : c);
    conns[s].push_back(2 * i);
    conns[t].push_back(2 * i + 1);
    return i;
  }
  ll pushFlow(int source, int sink) {
    for (ll res = 0;;) {
      calcDists(sink);
      if (dist[source] == -1) return res;
      for (int& v : act_ind) v = 0;
      res += INF - dfsFlow(source, sink, INF);
    }
  }
  vector<int> minCut() {
    vector<int> res;
    for (int i = 0; i < dist.size(); ++i) {
      if (dist[i] == -1) res.push_back(i);
    }
    return res;
  }
  ll getDirFlow(int i) const { return edges[2 * i + 1].a; }
  ll getUndirFlow(int i) const {
    return (edges[2 * i + 1].a - edges[2 * i].a) / 2;
  }
};
signed main() {
  4;
  cin.tie(nullptr)->sync_with_stdio(false);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n];
    Dinic d(m + n + 2);
    int src = m + n;
    int sink = m + n + 1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      d.addEdge(src, i, a[i]);
    }
    ll sum = 0;
    for (int i = 0; i < m; i++) {
      int x, y, c;
      cin >> x >> y >> c;
      sum += c;
      x--;
      y--;
      d.addEdge(x, n + i);
      d.addEdge(y, n + i);
      d.addEdge(n + i, sink, c);
    }
    cout << sum - d.pushFlow(src, sink);
  }
}
