#t516. 信使

信使

Messengers

Special for beginners, ^_^

Problem Description

During wartime there are nn outposts on the front line. Each outpost may be in communication with several other outposts. Messengers carry messages between outposts, which of course takes some time (measured in days). The headquarters is stationed at the first outpost. When headquarters issues an order, it sends several messengers to the outposts directly connected to it. Once an outpost receives a message, the messengers stationed there forward it to other outposts in the same way. The delivery succeeds only when all nn outposts have received the order. Because of careful preparation, each outpost has enough messengers (if an outpost communicates with kk other outposts, at least kk messengers are stationed there).

The commander-in-chief asks you to write a program that computes the minimum time needed to complete the whole delivery process.

Input Format

The first line contains two integers nn and mm separated by one space: there are nn outposts and mm communication lines. 1≤n≤1001\le n\le100.

Lines 22 through m+1m+1: each line has three integers i,j,ki,j,k separated by one space, meaning there is a communication line between outposts ii and jj, and that line takes kk days.

Output Format

One integer: the minimum time for the whole delivery process. If not all outposts can receive the message, output −1-1.

Sample Input 1

4 4
1 2 4
2 3 7
2 4 1
3 4 6

Sample Output 1

11

Constraints

1s, 1024KiB for each test case.