#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m, p;
struct NODE {
  long long lazy;
  long long sum;
  NODE() : lazy(-1) {}
} it[3000000];
long long len[3000000];
int S;
vector<pair<int, int> > in[3000000];
vector<pair<int, int> > out[3000000];
set<pair<int, int> > s;
void recalc(int now) {
  if (it[now].lazy >= 0)
    it[now].sum = it[now].lazy * len[now] % 1000000007;
  else
    it[now].sum = (it[now * 2].sum + it[now * 2 + 1].sum) % 1000000007;
}
void pushdown(int now) {
  if (it[now].lazy >= 0)
    it[now * 2].lazy = it[now].lazy, it[now * 2 + 1].lazy = it[now].lazy,
             it[now].lazy = -1;
  recalc(now * 2), recalc(now * 2 + 1);
}
void update(int now, int x, int y, int s, int e, long long v) {
  if (x > y) return;
  if (x == s && y == e) {
    it[now].lazy = v;
    recalc(now);
    return;
  }
  pushdown(now);
  update(now * 2, x, min(y, (s + e) / 2), s, (s + e) / 2, v);
  update(now * 2 + 1, max(x, (s + e) / 2 + 1), y, (s + e) / 2 + 1, e, v);
  recalc(now);
}
long long getsum(int now, int x, int y, int s, int e) {
  if (x > y) return 0;
  if (x == s && y == e) return it[now].sum;
  pushdown(now);
  return (getsum(now * 2, x, min(y, (s + e) / 2), s, (s + e) / 2) +
          getsum(now * 2 + 1, max(x, (s + e) / 2 + 1), y, (s + e) / 2 + 1, e)) %
         1000000007;
}
int main() {
  int i, j, k, l;
  cin >> n >> m >> p;
  for (i = 0; i < p; i++) {
    int x, y, z, w;
    scanf("%d%d%d%d", &x, &y, &z, &w);
    in[y].emplace_back(x, z);
    out[w + 1].emplace_back(x, z);
  }
  for (S = 1; S <= n + 2; S *= 2)
    ;
  for (i = S; i < S * 2; i++) len[i] = 1, it[i].lazy = 0;
  for (i = S - 1; i > 0; i--) len[i] = len[i * 2] + len[i * 2 + 1];
  update(1, 1, 1, 0, S - 1, 1);
  for (auto e : in[1]) s.insert(e);
  for (i = 1; i <= m; i++) {
    sort((in[i]).begin(), (in[i]).end());
    reverse((in[i]).begin(), (in[i]).end());
    for (auto e : in[i]) {
      auto ix = s.lower_bound(make_pair(e.second + 2, -0x3f3f3f3f));
      int tar = 1;
      if (ix != s.begin()) tar = prev(ix)->second + 1;
      long long res = getsum(1, tar, e.second + 1, 0, S - 1);
      update(1, e.second + 1, e.second + 1, 0, S - 1, res);
    }
    for (auto e : out[i]) s.erase(e);
    for (auto e : in[i]) update(1, e.first, e.second, 0, S - 1, 0), s.insert(e);
  }
  cout << getsum(1, s.size() ? prev(s.end())->second + 1 : 1, n, 0, S - 1);
  return 0;
}
