use std::io::*;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, m) = i.read();

    let mut uf = UnionFind::new(n);
    let mut ans = n;

    for _ in 0..m {
        let (x, y, _z) = i.read::<(usize, usize, usize)>();
        if uf.unite(x - 1, y - 1) {
            ans -= 1;
        }
    }
    writeln!(o, "{}", ans).unwrap();
}

struct UnionFindNode {
    parent: usize,
    depth: usize,
}

struct UnionFind(Vec<UnionFindNode>);
impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind(
            (0..n)
                .map(|i| UnionFindNode {
                    parent: i,
                    depth: 0,
                })
                .collect(),
        )
    }
    fn root(&self, mut i: usize) -> usize {
        loop {
            let p = self.0[i].parent;
            if p == i {
                return i;
            }
            i = p;
        }
    }
    fn unite(&mut self, i0: usize, i1: usize) -> bool {
        let mut r0 = self.root(i0);
        let mut r1 = self.root(i1);
        if r0 == r1 {
            return false;
        }
        if self.0[r0].depth > self.0[r1].depth {
            std::mem::swap(&mut r0, &mut r1);
        }
        self.0[r0].parent = r1;
        self.0[r1].depth = std::cmp::max(self.0[r1].depth, self.0[r0].depth + 1);
        true
    }
}


mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        b: Vec<u8>,
    }
    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                b: Vec::new(),
            }
        }
        pub fn read_word(&mut self) -> &[u8] {
            self.b.clear();
            let mut consume = 0;
            loop {
                self.r.consume(consume);
                let b = self.r.fill_buf().unwrap();
                assert!(b.len() != 0);
                if let Some(p) = b.iter().position(|&x| x == b' ' || x == b'\n') {
                    self.b.extend_from_slice(&b[..p]);
                    consume = p + 1;
                    break;
                }
                self.b.extend_from_slice(b);
                consume = b.len();
            }
            self.r.consume(consume);
            &self.b
        }
        pub fn read_word_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_word()) }
        }

        pub fn read<T: CpRead>(&mut self) -> T {
            T::cp_read(self)
        }
    }
    pub trait CpRead {
        fn cp_read<R: BufRead>(r: &mut CpReader<R>) -> Self;
    }

    impl CpRead for u64 {
        fn cp_read<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_u64_fast(&mut r.r)
        }
    }
    impl CpRead for i64 {
        fn cp_read<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_i64_fast(&mut r.r)
        }
    }

    macro_rules! cp_read_tuple {
        ($($t:ident),*) => {
            impl<$($t: CpRead),*> CpRead for ($($t),*) {
                fn cp_read<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    ($($t::cp_read(r)),*)
                }
            }
        };
    }

    macro_rules! cp_read_cast {
        ($t_self:ty, $t_read:ty) => {
            impl CpRead for $t_self {
                fn cp_read<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    <$t_read>::cp_read(r) as $t_self
                }
            }
        };
    }
    macro_rules! cp_read_parse {
        ($t:ty) => {
            impl CpRead for $t {
                fn cp_read<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    r.read_word_str().parse().unwrap()
                }
            }
        };
    }


    cp_read_cast!(usize, u64);
    cp_read_cast!(u32, u64);
    cp_read_cast!(u16, u64);
    cp_read_cast!(i32, i64);
    cp_read_cast!(i16, i64);
    cp_read_cast!(i8, i64);

    cp_read_parse!(f64);

    cp_read_tuple!(T1, T2);
    cp_read_tuple!(T1, T2, T3);
    cp_read_tuple!(T1, T2, T3, T4);
    cp_read_tuple!(T1, T2, T3, T4, T5);

    fn read_u64_fast<R: BufRead>(r: &mut R) -> u64 {
        let mut value = 0;
        loop {
            let mut idx = 0;
            let buf_len;
            {
                let buf = r.fill_buf().unwrap();
                buf_len = buf.len();
                assert!(buf_len != 0);
                while idx < buf_len && b'0' <= buf[idx] && buf[idx] <= b'9' {
                    value = value * 10 + (buf[idx] - b'0') as u64;
                    idx += 1;
                }
            }
            if idx < buf_len {
                r.consume(idx + 1);
                return value;
            }
            r.consume(idx);
        }
    }
    fn read_i64_fast<R: BufRead>(r: &mut R) -> i64 {
        let (consume, sign) = match r.fill_buf().unwrap()[0] {
            b'+' => (true, 1),
            b'-' => (true, -1),
            _ => (false, 1),
        };
        if consume {
            r.consume(1);
        }
        read_u64_fast(r) as i64 * sign
    }
}


Measured memory_bytes: 6396