#P1986. 元旦晚会

元旦晚会

Description

Brett’s class will perform as follows: all nn students stand in a line, each holding a microphone, singing in unison the theme of "Pleasant Goat and Big Big Wolf" (this act looks a bit silly).

The class is divided into mm voice parts. Each voice part consists of consecutive students. The ii-th voice part consists of students from aia_i to bib_i inclusive.

However, a student may belong to multiple voice parts, and some students may belong to none. To ensure singing quality, the ii-th voice part must have at least cic_i students holding microphones (that is, the number of students holding microphones within the ii-th voice part is at least cic_i).

Please compute the minimum number of microphones that Brett’s class needs.

Input Format

The first line contains two positive integers n,mn, m.

The next mm lines each contain three positive integers ai,bi,cia_i, b_i, c_i.

Output Format

Output a single positive integer: the minimum number of microphones required to satisfy all constraints.

11 5 
3 7 3 
8 10 3 
6 8 1 
1 3 1 
10 11 1 
6 

Hint

For 100%100\% of the testdata, it is guaranteed that n30000n \le 30000, m5000m \le 5000, 1ai<bin1 \le a_i < b_i \le n, and cibiai+1c_i \le b_i - a_i + 1.

Translated by ChatGPT 5