Haybale Guessing#10155

Haybale Guessing

1 second
128 megabytes
Hard

The cows, who always have an inferiority complex about their intelligence, have invented a new guessing game to sharpen their brains.

A designated "Hay Cow" hides behind the barn and creates uniquely sized stacks of hay bales, conveniently numbered 1, \ldots, n). Each stack contains between and 10^9 bales of hay.

The other cows then ask the Hay Cow a series of questions about the stacks. All questions have the following form:

The Hay Cow answers each query with a single integer , but the answers may not always be truthful.

Help the other cows determine whether the answers given by the Hay Cow are mutually consistent, or whether some answer contradicts the answers to previous queries.

Input

The first line contains two integers: n~(1 \le n \le 10^6) and q~(1 \le q \le 25000). Each of the next line contains three integers representing a query and its answer: q_l, q_h, and .

Output

Print one integer if all answers are consistent (i.e., if there exists a valid assignment of sizes to the hay stacks that agrees with all queries).

Otherwise, print the index of the earliest query, from to , whose answer is inconsistent with the answers to the preceding queries.

Examples

Example 1

Loading
Loading