import sys
n = int(sys.stdin.readline().rstrip())
m = int(sys.stdin.readline().rstrip())
node = [[] for _ in range(n+1)]
for i in range(m):
a , b = map(int,sys.stdin.readline().split(" "))
node[a].append(b)
node[b].append(a)
def DFS():
dfs = []
stack = [1]
visit = [False] *(n+1)
count = 0
while stack:
pop = stack.pop()
if(visit[pop] == False):
dfs.append(pop)
stack += node[pop]
visit[pop] = True
count += 1
return count-1
from collections import deque
def BFS():
queue = deque([1])
visit = [False] *(n+1)
visit[1] =True
count = 1
while queue:
pop = queue.popleft()
for no in node[pop]:
if(visit[no] == False):
queue.append(no)
visit[no] =True
count+=1
return count-1
print(DFS())
print(BFS())
dfs승
dfs 는 뺄 때 방문체크 / bfs 는 넣으면서 방문체크