시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB117394939405242.191%

문제

상근이는 자신의 결혼식에 학교 동기 중 자신의 친구와 친구의 친구를 초대하기로 했다. 상근이의 동기는 모두 N명이고, 이 학생들의 학번은 모두 1부터 N까지이다. 상근이의 학번은 1이다.

상근이는 동기들의 친구 관계를 모두 조사한 리스트를 가지고 있다. 이 리스트를 바탕으로 결혼식에 초대할 사람의 수를 구하는 프로그램을 작성하시오.

입력

첫째 줄에 상근이의 동기의 수 n (2 ≤ n ≤ 500)이 주어진다. 둘째 줄에는 리스트의 길이 m (1 ≤ m ≤ 10000)이 주어진다. 다음 줄부터 m개 줄에는 친구 관계 ai bi가 주어진다. (1 ≤ ai < bi ≤ n) ai와 bi가 친구라는 뜻이며, bi와 ai도 친구관계이다. 

출력

첫째 줄에 상근이의 결혼식에 초대하는 동기의 수를 출력한다.

예제 입력 1

6
5
1 2
1 3
3 4
2 3
4 5

예제 출력 1

3

예제 입력 2

6
5
2 3
3 4
4 5
5 6
2 5

예제 출력 2

0

힌트

예제 1의 경우 2와 3은 상근이의 친구이다. 또, 3과 4는 친구이기 때문에, 4는 상근이의 친구의 친구이다. 5와 6은 친구도 아니고, 친구의 친구도 아니다. 따라서 2, 3, 4 3명의 친구를 결혼식에 초대한다.

W3sicHJvYmxlbV9pZCI6IjU1NjciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFjYjBcdWQ2M2NcdWMyZGQiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzBjMVx1YWRmY1x1Yzc3NFx1YjI5NCBcdWM3OTBcdWMyZTBcdWM3NTggXHVhY2IwXHVkNjNjXHVjMmRkXHVjNWQwIFx1ZDU1OVx1YWQ1MCBcdWIzZDlcdWFlMzAgXHVjOTExIFx1Yzc5MFx1YzJlMFx1Yzc1OCBcdWNlNWNcdWFkNmNcdWM2NDAgXHVjZTVjXHVhZDZjXHVjNzU4IFx1Y2U1Y1x1YWQ2Y1x1Yjk3YyB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