#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Vector {
  double x, y, z;
} xyz[501000], r, h, w;
Vector operator+(const Vector &a, const Vector &b) {
  return (Vector){a.x + b.x, a.y + b.y, a.z + b.z};
}
Vector operator-(const Vector &a, const Vector &b) {
  return (Vector){a.x - b.x, a.y - b.y, a.z - b.z};
}
Vector operator*(const Vector &a, const double &b) {
  return (Vector){a.x * b, a.y * b, a.z * b};
}
Vector operator/(const Vector &a, const double &b) {
  return (Vector){a.x / b, a.y / b, a.z / b};
}
Vector operator^(const Vector &a, const Vector &b) {
  return (Vector){a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
                  a.x * b.y - a.y * b.x};
}
double operator&(const Vector &a, const Vector &b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}
inline double len(Vector a) { return sqrt(a & a); }
inline double getV(Vector a, Vector b, Vector c) { return a & (b ^ c); }
inline double getA(Vector a, Vector b, Vector c) {
  Vector x = a ^ c, y = a ^ b;
  return acos(x & y / len(x) / len(y));
}
long long n, m;
struct dinic {
  long long fst[501000], nxt[501000 << 4], to[501000 << 4], val[501000 << 4],
      cnt, s, t;
  void mem() {
    memset(fst, 0xff, sizeof(fst));
    cnt = -1;
  }
  void add(long long u, long long v, long long w) {
    nxt[++cnt] = fst[u], fst[u] = cnt, to[cnt] = v, val[cnt] = w;
  }
  long long vis[501000], tot, cur[501000], dep[501000], q[501000];
  long long bfs() {
    long long l = 1, r = 0;
    memset(dep, 0xff, sizeof(dep));
    vis[t] = ++tot, q[++r] = t;
    while (l <= r) {
      long long x = q[l++];
      for (long long i = fst[x]; i != -1; i = nxt[i])
        if (val[i ^ 1] && vis[to[i]] != tot) {
          vis[to[i]] = tot, dep[to[i]] = dep[x] + 1, q[++r] = to[i];
          if (to[i] == s) return 1;
        }
    }
    return vis[s] == tot;
  }
  long long dfs(long long x, long long a) {
    if (x == t || !a) return a;
    long long flow = 0, f;
    for (long long &i = cur[x]; i != -1; i = nxt[i]) {
      if (val[i] && dep[to[i]] == dep[x] - 1 &&
          (f = dfs(to[i], min(a, val[i])))) {
        val[i] -= f, val[i ^ 1] += f, flow += f, a -= f;
        if (!a) break;
      }
    }
    return flow;
  }
  long long solve() {
    long long ans = 0;
    long long f;
    while (bfs()) {
      for (long long i = 0; i <= 501000 - 20; i++) cur[i] = fst[i];
      while (f = dfs(s, 1LL << 60)) ans += f;
    }
    return ans;
  }
} D;
signed main() {
  long long u, v, z, sum = 0;
  D.mem();
  n = read();
  m = read();
  D.s = 0, D.t = 3511;
  for (register long long i = (1); i <= (n); ++i) {
    long long x = read();
    D.add(i, D.t, x);
    D.add(D.t, i, 0);
  }
  for (long long i = 1; i <= m; i++) {
    long long x = read(), y = read(), z = read();
    D.add(D.s, n + i, z);
    D.add(n + i, D.s, 0);
    D.add(n + i, x, 1LL << 60);
    D.add(x, n + i, 0);
    D.add(n + i, y, 1LL << 60);
    D.add(y, n + i, 0);
    sum += z;
  }
  printf("%I64d", sum - D.solve());
}
