Super-Fast Circular Races

No attempts yetTime limit1sMemory limit128 MB

Problem

A racing club wants to break the record for the total number of tracks (segments) used across several circular races held at the same time. The city has nn intersections. Tracks connect intersections; every track is one-way, so it may be driven in one fixed direction only.

The club will hold one or more races. Each race runs around a single closed loop of tracks (a directed cycle), going round and round. For safety, no two races may share a track or an intersection, and no race may pass through the same intersection twice. In other words, the chosen races form a set of vertex-disjoint and edge-disjoint simple directed cycles.

The club wants the total number of tracks used by all races to equal exactly nn (the previous record was n1n-1). A single simple directed cycle uses as many tracks as the intersections it visits, so a total of nn tracks means every intersection is visited by exactly one race.

Each intersection has at most two outgoing tracks and at most two incoming tracks. No track starts and ends at the same intersection.

Decide whether such an arrangement of races (with total length exactly nn) exists, and if so, count the number of different arrangements. Print the uppercase word NIE if it is impossible; otherwise print the number of arrangements modulo 1000010000.

Input

The first line contains two integers nn and mm separated by a space (1n100001 \le n \le 10000, 1m200001 \le m \le 20000). Here nn is the number of intersections and the target total track length, and mm is the number of tracks. Each of the next mm lines contains two integers pp and qq separated by a space, describing a one-way track that leaves intersection pp and ends at intersection qq.

Output

If no arrangement of races with total length nn exists, print the single word NIE. Otherwise print one integer: the number of such arrangements modulo 1000010000.