Donut Decoration

No attempts yetTime limit5sMemory limit512 MB

Problem

Mr. D fries NN donuts before sunrise. A freshly fried donut cannot go into the display case as it is. It has to be decorated first: filled with cream, dipped in chocolate, covered with toppings.

There are KK decoration tasks, numbered 11 through KK. A donut becomes a sellable item only if it receives tasks 1,2,,K1, 2, \dots, K exactly once each, in that order.

Mr. D lined the NN donuts up in a row and started working. He was up late the night before, so on each task he touched only the donuts lying in one contiguous interval. He did some tasks several times, left other tasks undone, and mixed up the order. A donut that did not go through the correct process cannot be sold, so he has to throw it away.

The work he did was recorded in the order he actually did it. Each record holds the interval [l,r][l, r] of the donuts he decorated and the task number xx. Given the record, count the donuts that can go into the display case as sellable items.

Input

The input is a single test case in the following format.

N K
T
l_1 r_1 x_1
...
l_T r_T x_T

The first line contains the number of donuts NN that Mr. D fried and the number of decoration tasks KK. (1N2000001 \le N \le 200000, 1K2000001 \le K \le 200000)

The second line contains the number of recorded tasks TT. (1T2000001 \le T \le 200000)

Each of the next TT lines describes one task, in the order Mr. D actually did it. The ii-th of these lines contains three integers lil_i, rir_i, xix_i. It means that the ii-th task applied task number xix_i once to every donut from the lil_i-th to the rir_i-th from the left. (1liriN1 \le l_i \le r_i \le N, 1xiK1 \le x_i \le K)

Output

Print the number of donuts that can be sold as items.