// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, 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! debug {
//     ($x: expr) => {
//         println!("[line({})] {}: {:?}", line!(), stringify!($x), $x)
//     };
// }
macro_rules! debug { ($x: expr) => () }

// from wata's template
macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display,
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::mem::swap;

use std::clone::Clone;
use std::cmp::Ordering;
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
struct Edge<Cost>
where
    Cost: std::clone::Clone,
{
    to: usize,
    cost: Cost,
}

impl<Cost> Ord for Edge<Cost>
where
    Cost: Ord + std::clone::Clone,
{
    fn cmp(&self, other: &Edge<Cost>) -> Ordering {
        (self.cost).cmp(&(other.cost)).reverse()
    }
}

impl<Cost> PartialOrd for Edge<Cost>
where
    Cost: std::clone::Clone,
    Edge<Cost>: Ord,
{
    fn partial_cmp(&self, other: &Edge<Cost>) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

trait Graph
where
    Self::Cost: Clone,
{
    type Cost;
    fn len(&self) -> usize;
    fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Self::Cost>>;
    fn get_order(&self) -> Vec<usize>;
}

#[derive(Clone, Debug, Hash)]
struct AdjList<Cost: Clone> {
    adj: Vec<Vec<Edge<Cost>>>,
}

impl<Cost: Clone> std::ops::Index<usize> for AdjList<Cost> {
    type Output = Vec<Edge<Cost>>;

    fn index(&self, i: usize) -> &Vec<Edge<Cost>> {
        &self.adj[i]
    }
}

impl<Cost: Clone> std::ops::IndexMut<usize> for AdjList<Cost> {
    fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec<Edge<Cost>> {
        &mut self.adj[i]
    }
}

impl<Cost: Clone> AdjList<Cost> {
    fn new(n: usize) -> AdjList<Cost> {
        AdjList {
            adj: vec![vec![]; n],
        }
    }

    fn add_edge(&mut self, from: usize, to_: usize, cost_: Cost) {
        self.adj[from].push(Edge {
            to: to_,
            cost: cost_,
        });
    }

    fn add_uedge(&mut self, from: usize, to_: usize, cost_: Cost) {
        self.add_edge(from, to_, cost_.clone());
        self.add_edge(to_, from, cost_);
    }
}

impl<Cost> Graph for AdjList<Cost>
where
    Cost: Clone,
{
    type Cost = Cost;

    fn len(&self) -> usize {
        self.adj.len()
    }

    fn get<'a>(&'a self, p: usize) -> std::slice::Iter<'a, Edge<Cost>> {
        self.adj[p].iter()
    }

    fn get_order(&self) -> Vec<usize> {
        let mut res = Vec::with_capacity(self.len());
        let mut deg = vec![0; self.len()];
        let mut used = vec![false; self.len()];
        for from in 0..self.len() {
            for e in self.get(from) {
                deg[e.to] += 1;
            }
        }
        for s in 0..self.len() {
            if deg[s] != 0 || used[s] {
                continue;
            }
            let mut stack = Vec::new();
            used[s] = true;
            stack.push(s);
            while let Some(p) = stack.pop() {
                used[p] = true;
                res.push(p);
                for e in self.get(p) {
                    deg[e.to] -= 1;
                    if deg[e.to] == 0 {
                        stack.push(e.to);
                    }
                }
            }
        }
        // debug!(deg);
        res
    }
}

// --------------------

trait Zero {
    fn zero() -> Self;
}

impl Zero for i64 {
    fn zero() -> i64 {
        0
    }
}

trait Max {
    fn max_value() -> Self;
}

impl Max for i64 {
    fn max_value() -> i64 {
        std::i64::MAX
    }
}

trait GraphHavingOrderedCost: Graph
where
    Self::Cost: Ord + Add<Self::Cost, Output = Self::Cost> + Zero + Max + Copy,
{
    fn get_shortest_path(&self, from: usize) -> (Vec<Self::Cost>, Vec<usize>);
    fn bellmanford(&self, from: usize) -> (Vec<Self::Cost>, Vec<bool>);
    fn get_shortest_path_graph(&self, from: usize, dist: &Vec<Self::Cost>) -> AdjList<Self::Cost>;
}

use std::ops::Add;
impl<T> GraphHavingOrderedCost for T
where
    T: Graph,
    T::Cost: Ord + Add<T::Cost, Output = T::Cost> + Zero + Max + Copy,
    Edge<T::Cost>: Ord,
{
    fn get_shortest_path(&self, from: usize) -> (Vec<Self::Cost>, Vec<usize>) {
        let n = self.len();

        let mut dist = vec![Self::Cost::max_value(); n];
        let mut pre = vec![n as usize; n];
        let mut heap = std::collections::BinaryHeap::new();
        heap.push(Edge {
            to: from,
            cost: Self::Cost::zero(),
        });
        dist[from] = Self::Cost::zero();
        while let Some(p) = heap.pop() {
            for e in self.get(p.to) {
                if p.cost + e.cost >= dist[e.to] {
                    continue;
                }
                heap.push(Edge {
                    to: e.to,
                    cost: p.cost + e.cost,
                });
                dist[e.to] = p.cost + e.cost;
                pre[e.to] = p.to;
            }
        }
        (dist, pre)
    }

    fn bellmanford(&self, from: usize) -> (Vec<Self::Cost>, Vec<bool>) {
        let n = self.len();
        let mut dist = vec![Self::Cost::max_value(); n];
        let mut updated = vec![true; n];
        dist[from] = Self::Cost::zero();
        for _ in 0..n + 1 {
            updated = vec![false; n];
            for from in 0..n {
                if dist[from] == Self::Cost::max_value() {
                    continue;
                }
                for e in self.get(from) {
                    if dist[e.to] > dist[from] + e.cost {
                        dist[e.to] = dist[from] + e.cost;
                        updated[e.to] = true;
                    }
                }
            }
        }
        (dist, updated)
    }

    fn get_shortest_path_graph(&self, from: usize, dist: &Vec<Self::Cost>) -> AdjList<Self::Cost> {
        let n = self.len();

        let mut res = AdjList::new(n);
        for from in 0..n {
            for e in self.get(from) {
                if dist[from] + e.cost == dist[e.to] {
                    res.add_edge(from, e.to, e.cost);
                }
            }
        }
        res
    }
}

impl<Cost> AdjList<Cost>
where
    Cost: Ord + Add<Cost, Output = Cost> + Zero + Max + Copy,
{
    fn construct_mst(&self) -> (Cost, AdjList<Cost>) {
        let mut edges: Vec<_> = self
            .adj
            .iter()
            .enumerate()
            .flat_map(|(i, x)| x.iter().map(move |e| (e.clone(), i)))
            .collect();
        // slow!!!!!!!!!!!
        edges.sort();
        let mut uft = UnionFind::new(self.len());
        let mut mst = AdjList::new(self.len());
        let mut cost_sum = Cost::zero();
        for (edge, from) in edges {
            let to = edge.to;
            if !uft.same(from, to) {
                uft.unite(from, to);
                mst.add_uedge(from, to, edge.cost);
                cost_sum = cost_sum + edge.cost;
            }
        }
        (cost_sum, mst)
    }
}

#[derive(Clone, Hash, Debug)]
struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            par: vec,
            rank: vec![0; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] {
            x
        } else {
            let par = self.par[x];
            let res = self.find(par);
            self.par[x] = res;
            res
        }
    }

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

    fn unite(&mut self, a: usize, b: usize) {
        let apar = self.find(a);
        let bpar = self.find(b);
        if self.rank[apar] > self.rank[bpar] {
            self.par[bpar] = apar;
        } else {
            self.par[apar] = bpar;
            if self.rank[apar] == self.rank[bpar] {
                self.rank[bpar] += 1;
            }
        }
    }
}

impl<Cost: Clone> AdjList<Cost> {
    fn vizualize(&self, name: &str) {
        let path = std::path::Path::new("tmp.dot");
        {
            use std::io::{BufWriter, Write};

            let file = std::fs::File::create(path).unwrap();
            let mut out = BufWriter::new(file);
            let n = self.len();
            writeln!(&mut out, "digraph graph_name {{").unwrap();
            for p in 0..n {
                writeln!(&mut out, "    {}[];", p);
            }
            for p in 0..n {
                for e in &self[p] {
                    writeln!(&mut out, "    {} -> {}", p, e.to);
                }
            }
            writeln!(&mut out, "}}");
        }
        let mut cmd = std::process::Command::new("dot");
        cmd.arg("-T");
        cmd.arg("png");
        cmd.arg("tmp.dot");
        cmd.arg("-o");
        cmd.arg(name);
        cmd.status().expect("failed to execute dot");
    }
}

impl<Cost: Clone + std::fmt::Display> AdjList<Cost> {
    fn viz_with_cost(&self, name: &str) {
        let path = std::path::Path::new("tmp.dot");
        {
            use std::io::{BufWriter, Write};

            let file = std::fs::File::create(path).unwrap();
            let mut out = BufWriter::new(file);
            let n = self.len();
            writeln!(&mut out, "digraph graph_name {{").unwrap();
            for p in 0..n {
                writeln!(&mut out, "    {}[];", p);
            }
            for p in 0..n {
                for e in &self[p] {
                    writeln!(&mut out, "    {} -> {} [label={}]", p, e.to, e.cost);
                }
            }
            writeln!(&mut out, "}}");
        }
        let mut cmd = std::process::Command::new("dot");
        cmd.arg("-T");
        cmd.arg("png");
        cmd.arg("tmp.dot");
        cmd.arg("-o");
        cmd.arg(name);
        cmd.status().expect("failed to execute dot");
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
struct Reverse<T>(T);

impl<T: PartialOrd> PartialOrd for Reverse<T> {
    fn partial_cmp(&self, other: &Reverse<T>) -> Option<std::cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Reverse<T> {
    fn cmp(&self, other: &Reverse<T>) -> std::cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

// impl AdjList<i64> {
//     fn solve(&self, cut: Vec<Vec<usize>>, root: uszie) -> 
// }

#[derive(Eq, PartialEq, Clone, Debug)]
enum Tree {
    Leaf(i64, usize),
    Node(i64, i64, Box<Tree>, Box<Tree>),
}

impl Tree {
    fn cost(&self) -> i64 {
        match self {
            &Tree::Leaf(x, ..) => x,
            &Tree::Node(x, ..) => x,
        }
    }

    fn unite_ids(&self, uf: &mut UnionFind) -> usize {
        match self {
            &Tree::Leaf(nc, nid) => {
                nid
            },
            &Tree::Node(nc, ec, ref l, ref r) => {
                let li = l.unite_ids(uf);
                let ri = r.unite_ids(uf);
                uf.unite(li, ri);
                uf.find(li)
            },
        }
    }

    fn solve<'a, 'b>(&'a self, st: &mut Vec<&'b Tree>)
    where
        'a: 'b,
    {
        match self {
            &Tree::Leaf(nc, nid) => {
                st.push(self);
            },
            &Tree::Node(nc, ec, ref l, ref r) => {
                if ec <= nc {
                    st.push(self);
                } else {
                    l.solve(st);
                    r.solve(st);
                }
            },
        }
    }
}



fn main() {
    use std::mem::replace;
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    #[allow(unused_macros)]
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    #[allow(unused_macros)]
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }

    input! {
        n: usize,
        m: usize,
        x: [i64; n],
        edges: [(usize, usize, i64); m],
    }

    let mut g = AdjList::new(n);
    for (f, t, c) in edges {
        g.add_uedge(f-1, t-1, c);
    }
    
    // let (_, mst) = g.construct_mst();
    let mut edges: Vec<_> = g.adj
        .iter()
        .enumerate()
        .flat_map(|(i, es)| es.iter().cloned().map(move |e| (e, i)))
        .collect();
    edges.sort();
    edges.reverse();
    let mut sts: Vec<_> = (0..n).map(|i| Some(Tree::Leaf(x[i], i))).collect();
    let mut uft = UnionFind::new(n);
    for (e, f) in edges.iter().cloned() {
        debug!((&e, &f));
        debug!(sts);
        let f = uft.find(f);
        let t = uft.find(e.to);
        if !uft.same(f, t) {
            uft.unite(f, t);
            let r = uft.find(f);
            let ft = replace(&mut sts[f], None).unwrap();
            let tt = replace(&mut sts[t], None).unwrap();
            sts[r] = Some(Tree::Node(ft.cost() + tt.cost(), e.cost, Box::new(ft), Box::new(tt)));
        }
    }

    let mut ss = Vec::new();
    let tr = sts.into_iter().filter(|x| x.is_some()).next().unwrap().unwrap();
    debug!(tr);
    tr.solve(&mut ss);
    debug!(ss);
    let mut uft = UnionFind::new(n);
    let mut cv = vec![0; n];
    for tr in &ss {
        let i = tr.unite_ids(&mut uft);
        cv[i] = tr.cost();

    }

    let mut ans = 0;
    for f in 0..n {
        for e in g[f].iter() {
            let t = e.to;
            debug!((f, t));
            if uft.same(f, t) {
                let r = uft.find(f);
                if cv[r] < e.cost {
                    ans += 1;
                }
            } else {
                ans += 1;
            }
        }
    }
    printfln!("{}", ans / 2);
}
