#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 19;
struct po {
  int x, f;
};
int n;
po dat[2 * MAX_N - 1];
void init(int n_) {
  n = 1;
  while (n < n_) n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) dat[i] = (po){0, 0};
}
void query(int a, int b, int k = 0, int l = 0, int r = n, int x = 0, int y = -1,
           int Y = -1) {
  po &pos = dat[k];
  if (r <= a || b <= l) {
    if (y > 0) {
      if (pos.f == 1 && pos.x != y - 1) pos.x = -1;
      if (pos.f == 0) pos.x = y;
      pos.f = 1;
    }
    return;
  }
  if (a <= l && r <= b) {
    if (k < n - 1 && Y == -1 && pos.x != x - 1) {
      query(a, b, k * 2 + 1, l, (l + r) / 2, x, y, -1);
      query(a, b, k * 2 + 2, (l + r) / 2, r, x, y, -1);
    }
    if ((Y < 0 && pos.x == x - 1) || (Y >= 0 && Y == x - 1))
      pos = (po){x, 1};
    else
      pos = (po){-1, Y != -1};
    return;
  }
  if (pos.f) {
    pos.f = 0;
    y = (y < 0 || pos.x == y - 1) ? pos.x : 1e6;
    Y = max(Y, y);
  }
  query(a, b, k * 2 + 1, l, (l + r) / 2, x, y, Y);
  query(a, b, k * 2 + 2, (l + r) / 2, r, x, y, Y);
}
int main() {
  int N, k;
  cin >> n >> k;
  N = n;
  init(n);
  int q;
  cin >> q;
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x;
    l--, r--;
    query(l, r + 1, 0, 0, n, x, -1);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    query(i, i + 1, 0, 0, n, k + 1, -1);
    if (dat[i + n - 1].x == k + 1) ans++;
  }
  cout << ans << endl;
  return 0;
}
