#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const long long INF = 10e17;
double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }
std::istream &operator>>(std::istream &in, set<int> &o) {
  int a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
struct Edge {
  int from, to;
  long long weight;
};
std::istream &operator>>(std::istream &in, Edge &o) {
  cin >> o.from >> o.to >> o.weight;
  o.from--;
  o.to--;
  return in;
}
class UnionFind {
 public:
  vector<int> parents;
  UnionFind(int n) { parents = vector<int>(n, -1); }
  int root(int a) {
    if (parents[a] < 0) {
      return a;
    }
    return parents[a] = root(parents[a]);
  }
  int size(int a) { return -parents[root(a)]; }
  bool connect(int a, int b) {
    int ra = root(a);
    int rb = root(b);
    if (ra == rb) {
      return false;
    }
    if (size(ra) < size(rb)) {
      swap(ra, rb);
    }
    parents[ra] += parents[rb];
    parents[rb] = ra;
    return true;
  }
  bool is_union(int a, int b) {
    int ra = root(a);
    int rb = root(b);
    return ra == rb;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> v(n);
  for (int i = 0; i < (n); ++i) cin >> v[i];
  vector<Edge> edges(m);
  for (Edge &p : edges) cin >> p;
  int ans = INT_MAX;
  for (int i = 0; i < (1 << m); ++i) {
    bool ok = [&] {
      vector<Edge> use_edges;
      for (int j = 0; j < (m); ++j)
        if ((i >> j) & 1) use_edges.push_back(edges[j]);
      vector<vector<long long>> edge_weights(n, vector<long long>(n, 0));
      for (Edge p : use_edges)
        edge_weights[p.from][p.to] = edge_weights[p.to][p.from] = p.weight;
      UnionFind uf(n);
      for (Edge e : use_edges) uf.connect(e.to, e.from);
      map<int, long long> w;
      long long now = 0;
      for (int x = 0; x < (n); ++x) w[uf.root(x)] += v[x];
      for (Edge e : use_edges)
        if (w[uf.root(e.from)] < e.weight) return false;
      return true;
    }();
    if (ok) ans = min(ans, m - __builtin_popcount(i));
  }
  cout << ans << endl;
}
