import sys
read = sys.stdin.readline
def bfs(start, dic):
queue = [start]
while(queue):
pop = queue.pop(0)
for i in dic[pop]:
if i not in visited:
visited.append(i)
queue.append(i)
def dfs(start, dic):
for i in dic[start]:
if i not in visited:
visited.append(i)
dfs(i, dic)
def dfs2(start, dic):
stack = [start]
while stack:
for i in dic[stack.pop()]:
if i not in visited:
visited.append(i)
stack.append(i)
visited = [1]
dic = {}
for i in range(int(read())):
dic[i + 1] = set()
for i in range(int(read())):
x1, x2 = list(map(int, read().split()))
dic[x1].add(x2)
dic[x2].add(x1)
# bfs(1, dic)
# dfs(1, dic)
dfs2(1, dic)
# print(visited)
print(len(visited) - 1)