Running Race

Find the maximum flow from node 0 to node N-1 in an undirected graph where road i has capacity 3^i, and print it modulo 1e9+7.

Hard8GraphShortest pathGreedyMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Minhyuk is organizing a running race. The city that hosts it has NN intersections, numbered 00 through N1N-1.

The city has MM roads, numbered 00 through M1M-1. Every road is bidirectional and joins two different intersections. No road joins an intersection to itself, and at most one road joins any given pair of intersections. The road network is not guaranteed to be connected, so two intersections may have no route between them at all.

The rule of the race is simple. A runner starts at intersection 00 and finishes at intersection N1N-1. Road ii carries at most 3i3^i people. Road 22, for example, carries at most 99 people, so the tenth person who tries to take road 22 cannot use it. Runners may share a road, but the number of people who pass along road ii never exceeds 3i3^i in total.

Given the roads, write a program that finds the largest number of people who can get from intersection 00 to intersection N1N-1.

Input

The first line contains the number of intersections NN and the number of roads MM. (2N20002 \le N \le 2000, 0M20000 \le M \le 2000)

Each of the next MM lines describes one road, in order, starting with road 00. Line i+2i+2 contains the two intersections aa and bb that road ii joins. (0a,b<N0 \le a, b < N, aba \ne b) No pair of intersections appears more than once.

Output

Print the largest number of people who can get from intersection 00 to intersection N1N-1, modulo 1,000,000,007.