#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
inline void chmax(T &t, U f) {
  if (t < f) t = f;
}
const long long SEG = 1 << 18;
pair<long long, long long> seg[SEG * 2];
pair<long long, long long> put[SEG * 2];
const pair<long long, long long> none(-100, -100);
const pair<long long, long long> fail(-10, -10);
inline void push(long long k) {
  if (put[k] == none) return;
  if (put[k] == fail) {
    seg[k] = fail;
  }
  if (seg[k].second + 1 == put[k].first) {
    seg[k].second = put[k].second;
  } else {
    seg[k] = fail;
  }
  if (k < SEG - 1) {
    for (long long i = 1; i <= 2; i++) {
      if (put[k * 2 + i] == none)
        put[k * 2 + i] = put[k];
      else if (put[k * 2 + i] == fail)
        continue;
      else if (put[k] == fail || put[k * 2 + i].second + 1 != put[k].first)
        put[k * 2 + i] = fail;
      else
        put[k * 2 + i].second = put[k].second;
    }
  }
  put[k] = none;
}
void update(long long a, long long b, pair<long long, long long> s,
            long long k = 0, long long l = 0, long long r = SEG) {
  push(k);
  if (r <= a || b <= l) return;
  if (a <= l && r <= b) {
    put[k] = s;
    push(k);
    return;
  }
  update(a, b, s, k * 2 + 1, l, (l + r) / 2);
  update(a, b, s, k * 2 + 2, (l + r) / 2, r);
}
signed main() {
  long long N, K;
  cin >> N >> K;
  for (long long i = 0; i < (SEG * 2); i++) {
    seg[i] = pair<long long, long long>(0, 0);
    put[i] = none;
  }
  long long Q;
  cin >> Q;
  while (Q--) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    update(a, b, pair<long long, long long>(c, c));
  }
  for (long long i = 0; i < (SEG - 1); i++) push(i);
  long long ans = 0;
  for (long long i = 0; i < (N); i++)
    if (seg[SEG - 1 + i] == pair<long long, long long>(0, K)) ans++;
  cout << ans << endl;
  return 0;
}
