N, M = map(int, input().split())
G: list = [[] for _ in range(N)]
for _ in range(M):
    ai, bi = map(int, input().split())
    G[ai - 1].append(bi - 1)
    G[bi - 1].append(ai - 1)

X: list = []

nodes = {i for i in range(N)}

while nodes:
    stack: list = []
    n = nodes.pop()
    stack.append(n)
    xi = 0
    while stack:
        cur = stack.pop()
        xi += 1
        for nx in G[cur]:
            if nx in nodes:
                stack.append(nx)
                nodes.remove(nx)
    X.append(xi)

ans = M - sum(xi - 1 for xi in X)

print(ans)
