cswork / OAOpen practice workspace

MicrosoftOA #12

Check Path Presence

Estimated EasyJudge-ready

Topics (AI-labelled)Hashing

Determine whether the graph contains a path 1—2—…—N made of direct edges. All vertices must be visited in ascending order, and a detour through other vertices cannot replace the direct edge between consecutive numbers.

Input

This site's input: the first line contains N M (1≤N≤100000, 0≤M≤200000), followed by M lines, each describing a simple undirected edge u v, with vertices numbered 1..N.

Output

Output a single integer, the answer.

Example 1

Input:

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

Output:

1

Example 2

Input:

3 2
1 3
3 2

Output:

0

Example 3

Input:

1 0

Output:

1

Example notes

Example 1: 1—2, 2—3, and 3—4 all exist, so output 1.

Example 2: the direct edge 1—2 is missing, so even though the graph is connected the required walk is impossible; output 0.

Example 3: a single vertex already forms the path and needs no edges; output 1.

Editorial

Loading solution…