There are N villages. Each village is numbered from 1 to N. The recent merger boom has resulted in several villages being merged. Two or more villages merged become one new city, and villages not merged with any village remain villages. You are given multiple pieces of information that two villages will become the same city after merging. Depending on the combination of information, three or more villages could become one city. Given information about villages that will become the same city after merging, output the absolute value of the difference between the number of cities and villages after merging.
[m,n] = map(int,input().split())

def find(v,cs):
    for c in cities:
        if v in c:
            return (True,c)
    return (False,set([v]))

cities = []
for _ in range(n):
    [a,b] = map(int,input().split())

    (ra,fa) = find(a,cities)
    (rb,fb) = find(b,cities)

    mg = fa | fb

    print(fa)

    if ra:
        cities.remove(fa)
    else:
        m = m - 1
    if rb:
        if fa != fb:
            cities.remove(fb)
    else:
        m = m - 1
    cities.append(mg)

print(abs(m-len(cities)))


[m,n] = map(int,input().split())

def find(v,cs):
    for c in cities:
        if v in c:
            return (True,c)
    return (False,set([v]))

cities = []
for _ in range(n):
    [a,b] = map(int,input().split())

    (ra,fa) = find(a,cities)
    (rb,fb) = find(b,cities)

    mg = fa | fb

    if ra:
        cities.remove(fa)
    else:
        m = m - 1
    if rb:
        if fa != fb:
            cities.remove(fb)
    else:
        m = m - 1
    cities.append(mg)

print(abs(m-len(cities)))

