n,m=map(int,input().split()) query=[tuple(map(int,input().split())) for i in range(m)] class UnionFind: __slots__ = ['id', 'size'] def __init__(self, n): self.id = [-1] * n self.size = n def root(self, x): if self.id[x] < 0: return x else: self.id[x] = self.root(self.id[x]) return self.id[x] def find(self, x, y): return self.root(x) == self.root(y) def union(self, x, y, b): s1, s2 = self.root(x), self.root(y) if b==0: if s1 != s2: if s1 <= s2: self.id[s1] += self.id[s2] self.id[s2] = s1 else: self.id[s2] += self.id[s1] self.id[s1] = s2 self.size -= 1 return True else: self.id[s1] += self.id[s2] self.id[s2] = s1 return False uf = UnionFind(n) for s,t in query: # print(s,t) # print(uf.root(s-1),uf.root(t-1)) # for i in range(n): # print(uf.root(i)+1, end='') # print() if uf.id[uf.root(s-1)] == uf.id[uf.root(t-1)]: uf.union(uf.root(s-1),uf.root(t-1),0) elif uf.id[uf.root(s-1)]