import sys
import collections
input = sys.stdin.readline
queue = collections.deque([1])
n = int(input().rstrip())
graph = [[] for _ in range(n+1)]
visited = [False] * (n+1)
visited[1] = True
for _ in range(int(input().rstrip())):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
while queue:
now = queue.popleft()
for i in graph[now]:
if not visited[i]:
queue.append(i)
visited[i] = True
print(visited.count(True) - 1)
input = sys.stdin.readline
def dfs(v):
visited[v] = True
for i in graph[v]:
if not visited[i]:
dfs(i)
queue = collections.deque([1])
n = int(input().rstrip())
graph = [[] for _ in range(n+1)]
visited = [False] * (n+1)
visited[1] = True
for _ in range(int(input().rstrip())):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
while queue:
now = queue.popleft()
for i in graph[now]:
if not visited[i]:
queue.append(i)
visited[i] = True
print(visited.count(True) - 1)