// https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

struct UnionFind {
      n: usize,
      parent: Vec<usize>,
      count: Vec<usize>,
      weight: Vec<i64>
}

impl UnionFind {
     fn new(n: usize) -> Self {
           let mut p = vec![0; n];
           for i in 0..n {
                 p[i] = i;
           }
           UnionFind { n: n, parent: p, count: vec![1; n], weight: vec![0; n] }
     }

     fn find(&mut self, a: usize) -> usize {
           if self.parent[a] == a {
                 return a;
           }
           let par = self.parent[a];
           self.parent[a] = self.find(par);
           self.parent[a]
     }

     fn unite(&mut self, a: usize, b: usize) {
           let a = self.find(a);
           let b = self.find(b);
           if a == b {
                 return;
           }
           let ca = self.count[a];
           let cb = self.count[b];
           let total = ca + cb;
           let total_weight = self.weight[a] + self.weight[b];
           self.count[b] = total;
           self.count[a] = total;
           self.weight[b] = total_weight;
           self.weight[a] = total_weight;
           if ca < cb {
                 self.parent[a] = b;
           } else {
                 self.parent[b] = a;
           }
     }

     fn same(&mut self, a: usize, b: usize) -> bool {
           self.find(a) == self.find(b)
     }

     fn count(&mut self, a: usize) -> usize {
           let a = self.find(a);
           self.count[a]
     }
}

type Edge = (usize, usize, i64);

fn merge(u: usize, v: usize, uf: &mut UnionFind, pointer: &mut Vec<usize>, pending_edges: &mut Vec<Vec<Edge>>) {
    if uf.same(u, v) {
        return;
    }

    let gid0 = pointer[uf.find(u)];
    let gid1 = pointer[uf.find(v)];
    let newgid = ifv!(pending_edges[gid0].len() < pending_edges[gid1].len(), gid1, gid0);
    let oldgid = gid0+gid1-newgid;
    uf.unite(u, v);
    let idx = uf.find(u);
    pointer[idx] = newgid;

    let mut a = vec![];
    for &e in &pending_edges[oldgid] {
        a.push(e);
    }
    pending_edges[newgid].append(&mut a);
    pending_edges[oldgid].clear();
}

fn main() {
    input! {
        n: usize, m: usize,
        x: [i64; n],
        edges: [(usize1, usize1, i64); m]
    };
    let mut edges = edges;
    edges.sort_by_key(|&(u, v, y)| y);


    let mut pending_edges = vec![vec![]; n];
    let mut pointer = vec![0; n];

    let mut real_uf = UnionFind::new(n);
    let mut uf = UnionFind::new(n);
    for i in 0..n {
        pointer[i] = i;
        uf.weight[i] = x[i];
        real_uf.weight[i] = x[i];
    }


    for (u, v, y) in edges {
        if real_uf.same(u, v) {
            let rid = real_uf.find(u);
            if real_uf.weight[rid] < y {
                let gid = pointer[uf.find(u)];
                pending_edges[gid].push((u, v, y));
            }
        } else {
            let rid0 = real_uf.find(u);
            let rid1 = real_uf.find(v);

            let idx0 = uf.find(u);
            let idx1 = uf.find(v);
            if uf.weight[idx0] + uf.weight[idx1] < y {
                if !uf.same(u, v) {
                    merge(u, v, &mut uf, &mut pointer, &mut pending_edges);
                }
                let newgid = pointer[uf.find(u)];
                pending_edges[newgid].push((u, v, y));
            } else {
                merge(u, v, &mut uf, &mut pointer, &mut pending_edges);

                let idx = uf.find(u);
                let gid = pointer[idx];
                for &(pu, pv, _) in &pending_edges[gid] {
                    real_uf.unite(pu, pv);
                }
                pending_edges[gid].clear();
                real_uf.unite(u, v);
            }
        }
    }

    let idx = uf.find(0);
    let gid = pointer[idx];

    println!("{}", pending_edges[gid].len());
}
