#include <bits/stdc++.h>
using namespace std;
struct Chien {
  long long n;
  vector<map<long long, long long> > dat;
  vector<vector<long long> > laz;
  vector<long long> lax, lay, law;
  map<long long, long long> def;
  Chien() {}
  Chien(long long n_) { init(n_); }
  void init(long long n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.clear();
    dat.resize(2 * n - 1);
    laz.clear();
    laz.resize(2 * n - 1);
    law.clear();
    law.resize(2 * n - 1, 0);
    lax.clear();
    lax.resize(2 * n - 1, -1);
    lay.clear();
    lay.resize(2 * n - 1);
    construct(n_);
  }
  void construct(long long n_) {
    for (long long i = 0; i < n_; i++) dat[i + n - 1][0] = 1;
    for (long long i = n - 2; i >= 0; i--) {
      for (pair<long long, long long> p : dat[i * 2 + 1])
        dat[i][p.first] += p.second;
      for (pair<long long, long long> p : dat[i * 2 + 2])
        dat[i][p.first] += p.second;
    }
  }
  inline void eval(long long k) {
    if (law[k]) {
      if (k * 2 + 1 < n * 2 - 1) law[k * 2 + 1] = law[k * 2 + 2] = 1;
      dat[k].clear();
      return;
    }
    if (dat[k].empty()) return;
    if (lax[k] < 0) return;
    if (k * 2 + 1 < n * 2 - 1) {
      if (~lax[k * 2 + 1]) {
        if (lay[k * 2 + 1] == lax[k])
          lay[k * 2 + 1] = lay[k];
        else
          law[k * 2 + 1] = 1;
      } else
        lax[k * 2 + 1] = lax[k], lay[k * 2 + 1] = lay[k];
      if (~lax[k * 2 + 2]) {
        if (lay[k * 2 + 2] == lax[k])
          lay[k * 2 + 2] = lay[k];
        else
          law[k * 2 + 2] = 1;
      } else
        lax[k * 2 + 2] = lax[k], lay[k * 2 + 2] = lay[k];
    }
    long long tmp = dat[k][lax[k] - 1];
    dat[k].clear();
    if (!tmp) return;
    dat[k][lay[k]] = tmp;
    lax[k] = -1;
  }
  void rmv(map<long long, long long> m, long long k) {
    for (pair<long long, long long> p : m) {
      if (dat[k].count(p.first)) {
        dat[k][p.first] -= p.second;
        if (!dat[k][p.first]) dat[k].erase(p.first);
      }
    }
    if (k) rmv(m, (k - 1) / 2);
  }
  void add(map<long long, long long> m, long long k) {
    for (pair<long long, long long> p : m) dat[k][p.first] += p.second;
    if (k) add(m, (k - 1) / 2);
  }
  void update(long long a, long long b, long long x, long long k, long long l,
              long long r) {
    eval(k);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      if (lax[k] < 0)
        lax[k] = lay[k] = x;
      else if (lay[k] + 1 == x)
        lay[k] = x;
      else {
        rmv(dat[k], (k - 1) / 2);
        law[k] = 1;
        dat[k].clear();
      }
      if (k) {
        rmv(dat[k], (k - 1) / 2);
        eval(k);
        add(dat[k], (k - 1) / 2);
      }
      return;
    }
    update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    update(a, b, x, k * 2 + 2, (l + r) / 2, r);
  }
  void update(long long a, long long b, long long x) {
    update(a, b, x, 0, 0, n);
  }
};
signed main() {
  long long n, k, t;
  cin >> n >> k >> t;
  Chien ch(n);
  for (long long i = 0; i < t; i++) {
    long long l, r, x;
    cin >> l >> r >> x;
    ch.update(l - 1, r, x);
  }
  cout << ch.dat[0][k] << endl;
}
