def solve(city_arr, road_arr):
    # points = [road_arr[0][0],road_arr[0][1]]
    starts = [road[0] for road in road_arr]
    ends = [road[1] for road in road_arr]
    points = starts
    points.extend(ends)
    set_cities = set(points)
    used = [False for road in road_arr]
    is_end = True
    counta = 0
    idx = 0
    current = ends[0]
    used[0] = True
    while all(used):
        try:
            idx = starts.index(current)
            used[idx] = True
            current = ends[idx] if is_end else starts[idx]
        except:
            counta +=1
            try:
                idx = used.index(False)
                current = ends[idx] if is_end else starts[idx]
            except:
                counta += len(city_arr) - len(points) - 1
                return counta
    return counta

    
if __name__ == '__main__':
    num_cities, num_roads = [int(i) for i in input().split()]
    roads = [[int(i) for i in input().split()] for j in range(num_roads)]
    cities = range(1, num_cities + 1)
    ans = solve(cities, roads)
    print(ans)
