Mr. D fries N 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 K decoration tasks, numbered 1 through K. A donut becomes a sellable item only if it receives tasks 1,2,…,K exactly once each, in that order.
Mr. D lined the N 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] of the donuts he decorated and the task number x. Given the record, count the donuts that can go into the display case as sellable items.
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 N that Mr. D fried and the number of decoration tasks K. (1≤N≤200000, 1≤K≤200000)
The second line contains the number of recorded tasks T. (1≤T≤200000)
Each of the next T lines describes one task, in the order Mr. D actually did it. The i-th of these lines contains three integers li, ri, xi. It means that the i-th task applied task number xi once to every donut from the li-th to the ri-th from the left. (1≤li≤ri≤N, 1≤xi≤K)
Print the number of donuts that can be sold as items.