# https://www.acmicpc.net/problem/2606


from collections import deque


computers = int(input())
links = int(input())

graph = {}
for i in range(links):
    a, b = map(int, input().split())
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)

    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)

visited = []

q = deque([1])
while q:
    p = q.popleft()
    if p in visited:
        continue
    visited.append(p)
    for computer in graph[p]:
        q.append(computer)

print(visited)

print(len(visited)-1)
9fe1dc4ef5ea05e4f4eb86f0734707b9fdb6e7ba
<mask token>

<mask token>
for i in range(links):
    a, b = map(int, input().split())
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)
    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)
<mask token>
while q:
    p = q.popleft()
    if p in visited:
        continue
    visited.append(p)
    for computer in graph[p]:
        q.append(computer)
print(visited)
print(len(visited) - 1)

<mask token>
computers = int(input())
links = int(input())
graph = {}
for i in range(links):
    a, b = map(int, input().split())
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)
    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)
visited = []
q = deque([1])
while q:
    p = q.popleft()
    if p in visited:
        continue
    visited.append(p)
    for computer in graph[p]:
        q.append(computer)
print(visited)
print(len(visited) - 1)

from collections import deque
computers = int(input())
links = int(input())
graph = {}
for i in range(links):
    a, b = map(int, input().split())
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)
    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)
visited = []
q = deque([1])
while q:
    p = q.popleft()
    if p in visited:
        continue
    visited.append(p)
    for computer in graph[p]:
        q.append(computer)
print(visited)
print(len(visited) - 1)

# https://www.acmicpc.net/problem/2606


from collections import deque


computers = int(input())
links = int(input())

graph = {}
for i in range(links):
    a, b = map(int, input().split())
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)

    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)

visited = []

q = deque([1])
while q:
    p = q.popleft()
    if p in visited:
        continue
    visited.append(p)
    for computer in graph[p]:
        q.append(computer)

print(visited)

print(len(visited)-1)