import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


int N, M;
long[] X;
Tuple!(long, "y", int, "a", int, "b")[] E;

int V;
int[][] G;
long[] xs;
int[][] edges;

int dfs(int u) {
  int ret;
  bool ok;
  foreach (i; edges[u]) {
    if (xs[u] >= E[i].y) {
      ok = true;
    } else {
      ++ret;
    }
  }
  if (!ok) {
    foreach (v; G[u]) {
      ret += dfs(v);
    }
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      X = new long[N];
      foreach (u; 0 .. N) {
        X[u] = readLong();
      }
      E.length = M;
      foreach (i; 0 .. M) {
        E[i].a = readInt() - 1;
        E[i].b = readInt() - 1;
        E[i].y = readLong();
      }
      E.sort();
      
      auto uf = new int[N];
      uf[] = -1;
      V = N;
      G = new int[][N];
      auto ids = iota(N).array;
      auto us = new int[M];
      foreach (i; 0 .. M) {
        const ra = uf.root(E[i].a);
        const rb = uf.root(E[i].b);
        if (uf.connect(ra, rb)) {
          const r = uf.root(ra);
          G ~= [ids[ra], ids[rb]];
          ids[r] = V;
          ++V;
        }
        us[i] = ids[uf.root(ra)];
      }
      
      xs = new long[V];
      xs[0 .. N] = X[];
      foreach (u; N .. V) {
        xs[u] = xs[G[u][0]] + xs[G[u][1]];
      }
      edges = new int[][V];
      foreach (i; 0 .. M) {
        edges[us[i]] ~= i;
      }
      debug {
        writeln("G = ", G);
        writeln("xs = ", xs);
        writeln("edges = ", edges);
      }
      const ans = dfs(V - 1);
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
