#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc126_e

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Graph():

    def __init__(self):
        self.adjacency_dict = {}
    
    def add_vertex(self, v):
        self.adjacency_dict[v] = []

    def add_edge(self, v1, v2):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)

    def remove_edge(self, v1, v2):
        self.adjacency_dict[v1].remove(v2)
        self.adjacency_dict[v2].remove(v1)

    def remove_vertex(self,v):
        while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
        del adjacency_vertex[v]

    def get_vertexes(self):
        return self.adjacency_dict.keys()

    def get_edges(self, v):
        return self.adjacency_dict[v]

    def print_graph(self):
        print(self.adjacency_dict)


n, m = map(int, input().strip().split())
xyz = [list(map(int, input().strip().split())) for _ in range(m)]

g = Graph()
for i in range(n):
    g.add_vertex(i)
for i in range(m):
    g.add_edge(xyz[i][0]-1, xyz[i][1]-1)

res = 0
reached_nodes = [0 for _ in range(n)]
for i in g.get_vertexes():
    if reached_nodes[i] == 1:
        continue
    res += 1
    reached_nodes[i] = 1
    q = [i]
    while len(q) > 0:
        u = q.pop()
        for v in g.get_edges(u):
            if reached_nodes[v] == 1:
                continue
            q.append(v)
            reached_nodes[v] = 1

print(res) class Graph():

    def __init__(self):
        self.adjacency_dict = {}
    
    def add_vertex(self, v):
        self.adjacency_dict[v] = []

    def add_edge(self, v1, v2):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)

    def remove_edge(self, v1, v2):
        self.adjacency_dict[v1].remove(v2)
        self.adjacency_dict[v2].remove(v1)

    def remove_vertex(self,v):
        while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
        del adjacency_vertex[v]

    def get_vertexes(self):
        return self.adjacency_dict.keys()

    def get_edges(self, v):
        return self.adjacency_dict[v]

    def print_graph(self):
        print(self.adjacency_dict) Graph def __init__(self):
        self.adjacency_dict = {}
    
     __init__ self.adjacency_dict = {} self.adjacency_dict self adjacency_dict {} self self def add_vertex(self, v):
        self.adjacency_dict[v] = []

     add_vertex self.adjacency_dict[v] = [] self.adjacency_dict[v] self.adjacency_dict self adjacency_dict v [] self self v v def add_edge(self, v1, v2):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)

     add_edge self.adjacency_dict[v1].append(v2) self.adjacency_dict[v1].append self.adjacency_dict[v1] self.adjacency_dict self adjacency_dict v1 append v2 self.adjacency_dict[v2].append(v1) self.adjacency_dict[v2].append self.adjacency_dict[v2] self.adjacency_dict self adjacency_dict v2 append v1 self self v1 v1 v2 v2 def remove_edge(self, v1, v2):
        self.adjacency_dict[v1].remove(v2)
        self.adjacency_dict[v2].remove(v1)

     remove_edge self.adjacency_dict[v1].remove(v2) self.adjacency_dict[v1].remove self.adjacency_dict[v1] self.adjacency_dict self adjacency_dict v1 remove v2 self.adjacency_dict[v2].remove(v1) self.adjacency_dict[v2].remove self.adjacency_dict[v2] self.adjacency_dict self adjacency_dict v2 remove v1 self self v1 v1 v2 v2 def remove_vertex(self,v):
        while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
        del adjacency_vertex[v]

     remove_vertex while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
         self.adjacency_dict[v] != [] self.adjacency_dict[v] self.adjacency_dict self adjacency_dict v [] adjacency_vertex = self.adjacency_dict[v][-1] adjacency_vertex self.adjacency_dict[v][-1] self.adjacency_dict[v] self.adjacency_dict self adjacency_dict v -1 self.remove_edge(v, adjacency_vertex) self.remove_edge self remove_edge v adjacency_vertex del adjacency_vertex[v] adjacency_vertex[v] adjacency_vertex v self self v v def get_vertexes(self):
        return self.adjacency_dict.keys()

     get_vertexes return self.adjacency_dict.keys() self.adjacency_dict.keys() self.adjacency_dict.keys self.adjacency_dict self adjacency_dict keys self self def get_edges(self, v):
        return self.adjacency_dict[v]

     get_edges return self.adjacency_dict[v] self.adjacency_dict[v] self.adjacency_dict self adjacency_dict v self self v v def print_graph(self):
        print(self.adjacency_dict) print_graph print(self.adjacency_dict) print self.adjacency_dict self adjacency_dict self self n, m = map(int, input().strip().split()) n map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split m list(map(int, input().strip().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split xyz = [list(map(int, input().strip().split())) for _ in range(m)] xyz [list(map(int, input().strip().split())) for _ in range(m)] g = Graph() g Graph() Graph for i in range(n):
    g.add_vertex(i) i range(n) range n g.add_vertex(i) g.add_vertex g add_vertex i for i in range(m):
    g.add_edge(xyz[i][0]-1, xyz[i][1]-1) i range(m) range m g.add_edge(xyz[i][0]-1, xyz[i][1]-1) g.add_edge g add_edge xyz[i][0]-1 xyz[i][0] [i] xyz i 0 1 xyz[i][1]-1 xyz[i][1] [i] xyz i 1 1 res = 0 res 0 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 reached_nodes = [0 for _ in range(n)] reached_nodes [0 for _ in range(n)] for i in g.get_vertexes():
    if reached_nodes[i] == 1:
        continue
    res += 1
    reached_nodes[i] = 1
    q = [i]
    while len(q) > 0:
        u = q.pop()
        for v in g.get_edges(u):
            if reached_nodes[v] == 1:
                continue
            q.append(v)
            reached_nodes[v] = 1 i g.get_vertexes() g.get_vertexes g get_vertexes if reached_nodes[i] == 1:
        continue
     reached_nodes[i] == 1 reached_nodes[i] reached_nodes i 1 continue res += 1 res 1 reached_nodes[i] = 1 reached_nodes[i] reached_nodes i 1 q = [i] q [i] i while len(q) > 0:
        u = q.pop()
        for v in g.get_edges(u):
            if reached_nodes[v] == 1:
                continue
            q.append(v)
            reached_nodes[v] = 1 len(q) > 0 len(q) len q 0 u = q.pop() u q.pop() q.pop q pop for v in g.get_edges(u):
            if reached_nodes[v] == 1:
                continue
            q.append(v)
            reached_nodes[v] = 1 v g.get_edges(u) g.get_edges g get_edges u if reached_nodes[v] == 1:
                continue
             reached_nodes[v] == 1 reached_nodes[v] reached_nodes v 1 continue q.append(v) q.append q append v reached_nodes[v] = 1 reached_nodes[v] reached_nodes v 1 print(res) print res class Graph():

    def __init__(self):
        self.adjacency_dict = {}
    
    def add_vertex(self, v):
        self.adjacency_dict[v] = []

    def add_edge(self, v1, v2):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)

    def remove_edge(self, v1, v2):
        self.adjacency_dict[v1].remove(v2)
        self.adjacency_dict[v2].remove(v1)

    def remove_vertex(self,v):
        while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
        del adjacency_vertex[v]

    def get_vertexes(self):
        return self.adjacency_dict.keys()

    def get_edges(self, v):
        return self.adjacency_dict[v]

    def print_graph(self):
        print(self.adjacency_dict) class Graph():

    def __init__(self):
        self.adjacency_dict = {}
    
    def add_vertex(self, v):
        self.adjacency_dict[v] = []

    def add_edge(self, v1, v2):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)

    def remove_edge(self, v1, v2):
        self.adjacency_dict[v1].remove(v2)
        self.adjacency_dict[v2].remove(v1)

    def remove_vertex(self,v):
        while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
        del adjacency_vertex[v]

    def get_vertexes(self):
        return self.adjacency_dict.keys()

    def get_edges(self, v):
        return self.adjacency_dict[v]

    def print_graph(self):
        print(self.adjacency_dict) Graph q = [i] [i] q u = q.pop() q.pop() u n, m = map(int, input().strip().split()) map(int, input().strip().split()) n reached_nodes = [0 for _ in range(n)] [0 for _ in range(n)] reached_nodes res = 0 0 res res += 1 1 res m = map(int, input().strip().split()) map(int, input().strip().split()) m g = Graph() Graph() g xyz = [list(map(int, input().strip().split())) for _ in range(m)] [list(map(int, input().strip().split())) for _ in range(m)] xyz
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc126_e

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

class Graph():

    def __init__(self):
        self.adjacency_dict = {}
    
    def add_vertex(self, v):
        self.adjacency_dict[v] = []

    def add_edge(self, v1, v2):
        self.adjacency_dict[v1].append(v2)
        self.adjacency_dict[v2].append(v1)

    def remove_edge(self, v1, v2):
        self.adjacency_dict[v1].remove(v2)
        self.adjacency_dict[v2].remove(v1)

    def remove_vertex(self,v):
        while self.adjacency_dict[v] != []:
            adjacency_vertex = self.adjacency_dict[v][-1]
            self.remove_edge(v, adjacency_vertex)
        del adjacency_vertex[v]

    def get_vertexes(self):
        return self.adjacency_dict.keys()

    def get_edges(self, v):
        return self.adjacency_dict[v]

    def print_graph(self):
        print(self.adjacency_dict)


n, m = map(int, input().strip().split())
xyz = [list(map(int, input().strip().split())) for _ in range(m)]

g = Graph()
for i in range(n):
    g.add_vertex(i)
for i in range(m):
    g.add_edge(xyz[i][0]-1, xyz[i][1]-1)

res = 0
reached_nodes = [0 for _ in range(n)]
for i in g.get_vertexes():
    if reached_nodes[i] == 1:
        continue
    res += 1
    reached_nodes[i] = 1
    q = [i]
    while len(q) > 0:
        u = q.pop()
        for v in g.get_edges(u):
            if reached_nodes[v] == 1:
                continue
            q.append(v)
            reached_nodes[v] = 1

print(res)
