#include <bits/stdc++.h>
using namespace std;
struct node {
  int sum, w, p, q;
};
node tree[100010 * 4];
int n, m, v;
void build(int t, int l, int r) {
  tree[t].q = 0;
  tree[t].p = 0;
  tree[t].w = 0;
  tree[t].sum = 0;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(t * 2, l, mid);
  build(t * 2 + 1, mid + 1, r);
}
void clear(int t, int l, int r) {
  if (tree[t].q == -1) return;
  int mid = (l + r) / 2;
  tree[t * 2].p = tree[t].p;
  tree[t * 2].w = tree[t].w;
  if (tree[t * 2].w == 1) tree[t * 2].sum = mid - l + 1;
  tree[t * 2 + 1].p = tree[t].p;
  tree[t * 2 + 1].w = tree[t].w;
  if (tree[t * 2 + 1].w == 1) tree[t * 2 + 1].sum = r - mid;
  tree[t].q = -1;
}
void updata(int t, int l, int r, int left, int right, int k) {
  int mid = (l + r) / 2;
  if (left <= l && r <= right) {
    if (tree[t].w == -1) return;
    if (tree[t].q != -1) {
      if (tree[t].p == k - 1) {
        tree[t].p = k;
        if (tree[t].p == v) {
          tree[t].w = 1;
          tree[t].sum = r - l + 1;
        }
        return;
      } else {
        tree[t].w = -1;
        tree[t].sum = 0;
        return;
      }
    }
  }
  clear(t, l, r);
  if (left <= mid) updata(t * 2, l, mid, left, right, k);
  if (right > mid) updata(t * 2 + 1, mid + 1, r, left, right, k);
  if (tree[t * 2].w == 1 && tree[t * 2 + 1].w == 1) {
    tree[t].w = 1;
  }
  tree[t].sum = tree[t * 2].sum + tree[t * 2 + 1].sum;
  if (tree[t * 2].w == -1 && tree[t * 2 + 1].w == -1) tree[t].w = -1;
  if (tree[t * 2].p == tree[t * 2 + 1].p) tree[t].p = tree[t * 2].p;
}
int main() {
  freopen("d.in", "r", stdin);
  freopen("d.out", "w", stdout);
  scanf("%d%d", &n, &v);
  scanf("%d", &m);
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    updata(1, 1, n, l, r, k);
  }
  printf("%d\n", tree[1].sum);
  return 0;
}
