시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
5 초 1024 MB 24 14 10 71.429%

문제

Since you are in Britain, you definitely want to try British food. Unfortunately you will only have a single free evening, so you decided to try all the food you can get in one run. You plan a gigantic meal where you eat one British dish after the other. Clearly not every order of dishes is appropriate. For example, it is not acceptable to eat Blood Pudding directly after Cornish Hevva Cake, but it would be perfectly fine if you chose to eat Baked Beans in between.

You have compiled a comprehensive list of British dishes. For each dish you have also decided which other dishes are fit to be eaten directly afterwards. A menu is a sequence of dishes such that each dish (except the first) is fit to be eaten directly after the previous dish.

After some time studying the list of dishes, you noticed something odd: Whenever it is possible to find a menu in which a dish occurs twice (for example dishes A, then B, then C, then dish A again), there can be at most four different types of dishes between the dish that occurred twice – excluding that dish itself. For example, it is impossible to find a menu like A, B, C, D, E, F, A, but it may be possible to find menus like A, B, C, B, C, B, C, B, C, B, A or A, B, C, D, E, A, B, C, D, E, A.

But who wants to eat the same dish twice anyway? Clearly, you want to know how many dishes there can be in a menu without repeating any dish!

입력

The input consists of:

  • One line with two integers n, m (1 ≤ n ≤ 105 , 1 ≤ m ≤ 106 ), the number of dishes and compatibilities.
  • m lines, each containing two integers a and b (1 ≤ a, b ≤ n), indicating that you can eat dish b immediately after dish a.

Dishes are numbered from 1 to n in no particular order, and the compatibilities satisfy the constraint described above.

출력

A single integer indicating the maximum number of courses in a menu without repeated dishes.

예제 입력 1

4 3
1 2
2 3
2 4

예제 출력 1

3

예제 입력 2

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

예제 출력 2

6

힌트