#include <bits/stdc++.h>
using namespace std;
struct segtree {
  int n;
  vector<pair<int, int> > lazy;
  segtree(int sz) {
    n = 1;
    while (n < sz) n <<= 1;
    lazy.resize(2 * n - 1);
    for (int i = 0; i < 2 * n - 1; i++) lazy[i] = pair<int, int>(0, 0);
  }
  void eval(int k, pair<int, int> x, int l, int r) {
    if (x.second == 0) return;
    if (lazy[k].second == 0)
      lazy[k] = x;
    else if (lazy[k].second + 1 == x.first)
      lazy[k].second = x.second;
    else
      lazy[k] = pair<int, int>(1e9, 1e9);
  }
  void add(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      eval(k, pair<int, int>(x, x), l, r);
    } else {
      eval(k * 2 + 1, lazy[k], l, r);
      eval(k * 2 + 2, lazy[k], l, r);
      lazy[k] = pair<int, int>(0, 0);
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
    }
  }
};
int main() {
  int n, K, t, sum = 0;
  cin >> n >> K >> t;
  segtree S(n);
  for (int i = 0; i < t; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    S.add(l, r + 1, x);
  }
  for (int i = 0; i < n + 1; i++) S.add(i, i + 1, K + 1);
  for (int i = 0; i < n; i++) {
    if (S.lazy[i + S.n].first == 1 && S.lazy[i + S.n].second == K + 1) {
      sum++;
    }
  }
  cout << sum << endl;
}
