#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct segment {
  int left, right, x;
} tree[maxn << 2];
int n, m, q, ans;
void read(int &x) {
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
}
void cal(int p) {
  tree[p].x = (tree[p << 1].x == tree[(p << 1) + 1].x ? tree[p << 1].x : -2);
}
void build(int p, int L, int R) {
  tree[p].left = L;
  tree[p].right = R;
  if (L == R) return;
  int mid = (L + R) >> 1;
  build(p << 1, L, mid);
  build((p << 1) + 1, mid + 1, R);
}
void pushdown(int p) {
  if (tree[p].left < tree[p].right && tree[p].x > -2)
    tree[p << 1].x = tree[(p << 1) + 1].x = tree[p].x;
}
void change(int p, int L, int R, int x) {
  if (tree[p].x == -1) return;
  if (tree[p].left == L && tree[p].right == R && tree[p].x > -2) {
    if (x == tree[p].x + 1)
      tree[p].x = x;
    else
      tree[p].x = -1;
    pushdown(p);
    return;
  }
  pushdown(p);
  int mid = (tree[p].left + tree[p].right) >> 1;
  if (R <= mid)
    change(p << 1, L, R, x);
  else if (L > mid)
    change((p << 1) + 1, L, R, x);
  else
    change(p << 1, L, mid, x), change((p << 1) + 1, mid + 1, R, x);
  cal(p);
}
void dfs(int p) {
  if (tree[p].x < m && tree[p].x > -2) return;
  if (tree[p].x == m) {
    ans += tree[p].right - tree[p].left + 1;
    return;
  }
  dfs(p << 1);
  dfs((p << 1) + 1);
}
int main() {
  int i, L, R, x;
  for (i = 1, read(n), read(m), read(q), build(1, 1, n); i <= q; ++i)
    read(L), read(R), read(x), change(1, L, R, x);
  dfs(1);
  printf("%d\n", ans);
  return 0;
}
