Bridges

No attempts yetTime limit3sMemory limit512 MB

Problem

San Bytecisco is a beautifully situated coastal town. It consists of nn small but densely populated islands, numbered from 11 to nn. Some pairs of islands are joined by bridges that carry two-way (bidirectional) traffic. At most one bridge may connect any pair of islands. The islands are connected so that every island can be reached from every other island using the bridges alone.

Byteasar and Bytie are planning a bike trip in San Bytecisco. Starting from island 11, they want to visit every island, cross every bridge exactly once, and return to where they started, island 11. In other words, they are looking for a closed route (an Eulerian circuit) that begins at island 11, uses every bridge exactly once, and ends back at island 11.

The trouble is the wind. It is very windy along the coast, and especially so on the bridges. Depending on its speed and direction, the wind makes a bridge harder to cross, and to a different degree for each of the two directions. For every bridge and every direction of crossing, assume the opposing wind speed is constant.

Define the tiresomeness of a route as the maximum opposing wind speed among all the (bridge, direction) crossings it uses. Among all routes that satisfy the requirements, make this tiresomeness as small as possible, and report that minimum value.

Input

The first line contains two integers nn and mm separated by a single space (2n10002 \le n \le 1000, 1m20001 \le m \le 2000), the number of islands and the number of bridges. Islands are numbered from 11 to nn, and bridges from 11 to mm.

Each of the next mm lines describes one bridge. Line i+1i+1 contains four integers ai,bi,li,pia_i, b_i, l_i, p_i separated by single spaces (1ai,bin1 \le a_i, b_i \le n, aibia_i \ne b_i, 1li,pi10001 \le l_i, p_i \le 1000). Bridge ii connects islands aia_i and bib_i; the opposing wind speed is lil_i when crossing from aia_i to bib_i, and pip_i when crossing from bib_i to aia_i.

Output

If no route meeting the requirements exists, print NIE (Polish for 'no') on a single line. Otherwise, print a single integer: the minimum possible tiresomeness, that is, the smallest achievable maximum opposing wind speed over all valid routes.