#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
typedef map<int, vector<int>> mivi;
int dfs(int node, mivi& graph, vector<bool>& visit)
{
if (visit[node]) return 0;
visit[node] = true;
int count = 1;
for (int next : graph[node]) {
count += dfs(next, graph, visit);
}
return count;
}
int main() {
int n, c;
cin >> n >> c;
vector<bool> v = vector<bool>(n,false);
mivi g;
while (c--) {
int s, a;
cin >> s >> a;
g[s-1].push_back(a-1);
g[a - 1].push_back(s - 1);
}
int count = 0;
// dfs stack ver.
//v[0] = true;
//stack<int> s; s.push(0);
//while (!s.empty()) {
// int t = s.top(); s.pop();
// for (int next : g[t]) {
// if (v[next]) continue;
// s.push(next);
// v[next] = true;
// count++;
// }
//}
// dfs recur ver.
//count = dfs(0, g, v);
//count--; // 자기 자신 제외
// bfs
v[0] = true;
queue<int> q; q.push(0);
while (!q.empty()) {
int f = q.front(); q.pop();
for (int next : g[f]) {
if (v[next]) continue;
v[next] = true;
q.push(next);
count++;
}
}
cout << count;
}
dfs bfs 연습