Candy-collecting robot

Given a house graph with an integer capacity on every corridor, find the maximum number of unit-capacity routes from room 1 to room n.

Medium7GraphBFSImplementationMathNo attempts yetTime limit1sMemory limit512 MB

Problem

Seokhwan walks around the house and drops candy in the corridors. Seongwon builds a small cleaning robot to clean up the mess.

The house has nn rooms numbered 11 to nn and mm corridors. Each corridor connects two different rooms and can be walked in either direction. Candy lies only in corridors, and each corridor holds a fixed number of candies. Rooms hold no candy.

A robot follows a start room, a destination room, and a route entered by Seongwon. It moves only through corridors that still hold candy, and it picks up exactly 11 candy each time it passes through a corridor. Seongwon enters only routes that satisfy this condition.

Seongwon sends every robot from room 11 to room nn. Determine the largest number of robots that can be set up without taking more candies from any corridor than it holds.

Input

The first line contains the number of rooms nn (2n3002 \le n \le 300) and the number of corridors mm (1m50001 \le m \le 5000), separated by a space.

Each of the next mm lines contains corridor information. Each line contains three positive integers aa, bb, and cc, separated by spaces. They mean that the corridor connecting room aa and room bb holds cc candies. (aba \ne b, 1a,bn1 \le a, b \le n, 1c1001 \le c \le 100)

Output

Print the largest number of robots that can be sent from room 11 to room nn.