Meeting Time

No attempts yetTime limit1sMemory limit256 MB

Problem

Bessie and her sister Elsie want to travel from the barn to their favorite field. They want to leave the barn at exactly the same moment and reach the field at exactly the same moment.

The farm has NN fields (1N161 \le N \le 16) numbered 11 through NN. Field 11 holds the barn and field NN is the favorite field. The farm sits on the side of a hill, so field XX is higher than field YY whenever X<YX < Y. There are MM paths, each joining a pair of fields. Every path is steep enough that a cow can follow it only downhill. A path joining field 55 and field 88 can be followed from 55 to 88 but not the other way, because that direction is uphill. At most one path joins any pair of fields, so MN(N1)/2M \le N(N-1)/2.

Bessie and Elsie need different amounts of time on the same path. One path might cost Bessie 1010 units of time and Elsie 2020. The cows spend time only while walking a path. They are in a hurry, so they cross a field in zero time and never wait anywhere.

Find the smallest total time in which Bessie and Elsie can reach their favorite field at the same moment.

Input

The first line contains NN and MM, separated by a space.

Each of the next MM lines describes one path with four integers AA, BB, CC, DD. Fields AA and BB are the fields the path joins, with A<BA < B. The value CC is the time Bessie needs on that path and DD is the time Elsie needs. Both CC and DD are between 11 and 10001000.

Output

Print, on a single line, the minimum time in which both cows reach the favorite field at the same moment. If no such time exists, or if the cows cannot reach field NN at all, print IMPOSSIBLE on a single line. When N=1N = 1 the barn is already the favorite field, so print 00.

Hint

In the first example Bessie is twice as fast as Elsie on every path. Even so, if Bessie walks 1 -> 2 -> 3 and Elsie walks 1 -> 3, they arrive at the same moment.