P11151 [AOJ] Donut Decoration
普及
题目描述

Example

Input

3 2
3
1 2 1
2 3 2
3 3 1

Output

1

输入格式

见题面

输出格式

见题面

样例输入
3 2 3 1 2 1 2 3 2 3 3 1
样例输出
1