#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (int i = 0; i < (v.size()); i++) {
    os << v[i] << (i == v.size() - 1 ? "" : " ");
  }
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) {
    is >> x;
  }
  return is;
}
const int INF = 2000000000;
const int sqrtN = 512;
class sqdiv {
 public:
  int N, K;
  vector<int> data;
  vector<bool> lazy_flag;
  vector<int> lazy_update;
  sqdiv(int n) {
    N = n;
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    lazy_flag.assign(K, false);
    lazy_update.assign(K, 0);
  }
  void eval(int k) {
    if (lazy_flag[k]) {
      lazy_flag[k] = false;
      for (int i = k * sqrtN; i < (k + 1) * sqrtN; i++) {
        data[i] = data[i] + 1 == lazy_update[k] ? lazy_update[k] : INF;
      }
    }
  }
  void update(int x, int y, int a) {
    for (int k = 0; k < (K); k++) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= x || y <= l) continue;
      if (x <= l && r <= y) {
        lazy_flag[k] = true;
        lazy_update[k] = lazy_update[k] + 1 == a ? a : INF;
      } else {
        eval(k);
        for (int i = max(x, l); i < min(y, r); i++) {
          data[i] = data[i] + 1 == a ? a : INF;
        }
      }
    }
  }
  int find(int a) {
    int k = a / sqrtN;
    eval(k);
    return data[a];
  }
};
int main() {
  int n, k, t;
  cin >> n >> k >> t;
  sqdiv s(n);
  for (int i = 0; i < (t); i++) {
    int l, r, x;
    cin >> l >> r >> x;
    l--;
    s.update(l, r, x);
  }
  int cnt = 0;
  for (int i = 0; i < (n); i++) {
    if (s.find(i) == k) cnt++;
  }
  cout << cnt << endl;
}
