#P1986. Minimum Microphones

    ID: 15268 Type: Default 1000ms 256MiB

Minimum Microphones

Minimum Microphones

Brett's class has a performance where each of the nn students stands in a row holding a microphone while singing a song. The class is divided into mm contiguous groups, where the ii-th group consists of students with indices from aia_i to bib_i (inclusive). Note that a student may belong to multiple groups or none at all. To ensure a good performance, each group must have at least cic_i students holding microphones. Your task is to determine the minimum number of microphones required.

inputFormat

The first line contains two integers nn and mm. Each of the following mm lines contains three integers aia_i, bib_i, and cic_i, representing the starting and ending indices of the ii-th group and the minimum number of microphones required for that group, respectively.

outputFormat

Output a single integer, the minimum number of microphones needed.

sample

5 2
1 3 2
4 5 1
3