#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
const int B = 450;
int s[B][B] = {};
int F[B];
int T[B];
bool bad[B] = {};
void push(int bid) {
  if (bad[bid]) {
    for (int(i) = 0; (i) < (int)(B); ++(i)) s[bid][i] = -1;
    return;
  }
  if (F[bid] == -1) return;
  for (int(i) = 0; (i) < (int)(B); ++(i)) {
    if (s[bid][i] == F[bid])
      s[bid][i] = T[bid];
    else
      s[bid][i] = -1;
  }
  F[bid] = -1;
  T[bid] = -1;
}
void D(int l, int r, int x) {
  int lid = l / B, rid = r / B;
  if (lid == rid) {
    push(lid);
    for (int i = l; i <= r; ++i) {
      if (s[i / B][i % B] == x - 1)
        s[i / B][i % B] = x;
      else
        s[i / B][i % B] = -1;
    }
  } else {
    push(lid);
    push(rid);
    for (int i = l; i < B * (lid + 1); ++i) {
      if (s[i / B][i % B] == x - 1)
        s[i / B][i % B] = x;
      else
        s[i / B][i % B] = -1;
    }
    for (int bid = lid + 1; bid < rid; ++bid) {
      if (F[bid] == -1) {
        F[bid] = x - 1;
        T[bid] = x;
      } else {
        if (T[bid] == x - 1)
          T[bid] = x;
        else
          bad[bid] = true;
      }
    }
    for (int i = B * rid; i <= r; ++i) {
      if (s[i / B][i % B] == x - 1)
        s[i / B][i % B] = x;
      else
        s[i / B][i % B] = -1;
    }
  }
}
int main() {
  int n, k, t;
  scanf(" %d %d %d", &n, &k, &t);
  fill(F, F + B, -1);
  fill(T, T + B, -1);
  for (int(i) = 0; (i) < (int)(t); ++(i)) {
    int l, r, x;
    scanf(" %d %d %d", &l, &r, &x);
    --l;
    --r;
    D(l, r, x);
  }
  int ans = 0;
  for (int(i) = 0; (i) < (int)(n); ++(i)) ans += (s[i / B][i % B] == k);
  printf("%d\n", ans);
  return 0;
}
