Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/graf-qisqa-yollar-soni

Number of shortest paths

Medium 1000 ms 128 MB 47%
Share

A city with $n$ intersections and $m$ two-way streets is given; driving along each street takes $1$ minute. How many different paths lead from intersection $1$ to intersection $n$ in the shortest time? Two paths are different if their sequences of streets differ. Print the answer modulo $10^{9} + 7$; if $n$ cannot be reached, print $0$.

A graph of intersections: the equal-length shortest paths from the first to the last are highlighted

Input

The first line contains two integers: $n$ and $m$. Each of the next $m$ lines contains two positive integers: $u$ and $v$ — the vertices joined by an edge.

Output

One integer — the number of shortest paths modulo $10^{9} + 7$.

Note

$2 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le u, v \le n$, $u \ne v$
There is at most one street between any pair of intersections.

Examples

Input #1
6 7
1 2
1 3
2 4
3 4
4 6
2 5
5 6
Output #1
3
Input #2
4 2
1 2
3 4
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.