#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 200086;
int f[4 * N], mn[4 * N], mx[4 * N];
bool bo[4 * N], tag[4 * N];
int n, k, t, l, r, x, ans;
void pushdown(int i) {
  if (!bo[i * 2]) {
    if (tag[i * 2]) {
      if (mx[i] = mn[i * 2] + 1)
        mx[i * 2] = mx[i];
      else
        bo[i * 2] = 1;
    }
    tag[i * 2] = 1;
    mx[i * 2] = mx[i];
    mn[i * 2] = mn[i];
  }
  if (!bo[i * 2 + 1]) {
    if (tag[i * 2 + 1]) {
      if (mx[i] = mn[i * 2 + 1] + 1)
        mx[i * 2 + 1] = mx[i];
      else
        bo[i * 2] = 1;
    }
    tag[i * 2 + 1] = 1;
    mx[i * 2 + 1] = mx[i];
    mn[i * 2 + 1] = mn[i];
  }
  tag[i] = 0;
  mn[i] = 0;
  mx[i] = 0;
}
void upd(int i, int l, int r, int ll, int rr, int x) {
  if (bo[i]) return;
  if (ll <= l && r <= rr) {
    if (tag[i]) {
      if (x != mx[i] + 1) {
        bo[i] = 1;
        return;
      }
      mx[i] = x;
      return;
    }
    tag[i] = true;
    mx[i] = x;
    mn[i] = x;
    return;
  }
  if (tag[i]) pushdown(i);
  int mid = (l + r) / 2;
  if (ll <= mid) upd(i * 2, l, mid, ll, rr, x);
  if (mid + 1 <= rr) upd(i * 2 + 1, mid + 1, r, ll, rr, x);
}
void cnt(int i, int l, int r) {
  if (bo[i]) return;
  if (l == r) {
    if (mx[i] == k) ans++;
    return;
  }
  if (tag[i]) pushdown(i);
  int mid = (l + r) / 2;
  cnt(i * 2, l, mid);
  cnt(i * 2 + 1, mid + 1, r);
}
int main() {
  n = read();
  k = read();
  t = read();
  for (int i = 1; i <= t; i++) {
    l = read();
    r = read();
    x = read();
    upd(1, 1, n, l, r, x);
  }
  ans = 0;
  cnt(1, 1, n);
  cout << ans << endl;
  return 0;
}
