#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 1000005;
vector<pair<int, int> > pi[maxn], po[maxn];
set<pair<int, int> > mt;
int n, m, q;
bool zr[maxn << 2];
int sum[maxn << 2];
void pushdown(int i) {
  if (zr[i]) {
    sum[i << 1] = sum[i << 1 | 1] = 0;
    zr[i << 1] = zr[i << 1 | 1] = 1;
    zr[i] = 0;
  }
}
void pushup(int i) {
  sum[i] = sum[i << 1] + sum[i << 1 | 1],
  sum[i] -= sum[i] >= 1000000007 ? 1000000007 : 0;
}
void modify(int i, int l, int r, int ps, int v) {
  if (l == r) return void(sum[i] = v);
  pushdown(i);
  int mid = l + r >> 1;
  if (ps <= mid)
    modify(i << 1, l, mid, ps, v);
  else
    modify(i << 1 | 1, mid + 1, r, ps, v);
  pushup(i);
}
int query(int i, int l, int r, int fr, int bh) {
  if (fr > bh) return 0;
  if (l == fr && r == bh) return sum[i];
  pushdown(i);
  int mid = l + r >> 1;
  if (bh <= mid)
    return query(i << 1, l, mid, fr, bh);
  else if (fr > mid)
    return query(i << 1 | 1, mid + 1, r, fr, bh);
  else
    return (query(i << 1, l, mid, fr, mid) +
            query(i << 1 | 1, mid + 1, r, mid + 1, bh)) %
           1000000007;
}
void clear(int i, int l, int r, int fr, int bh) {
  if (l == fr && r == bh) {
    zr[i] = 1;
    sum[i] = 0;
    return;
  }
  pushdown(i);
  int mid = l + r >> 1;
  if (bh <= mid)
    clear(i << 1, l, mid, fr, bh);
  else if (fr > mid)
    clear(i << 1 | 1, mid + 1, r, fr, bh);
  else
    clear(i << 1, l, mid, fr, mid), clear(i << 1 | 1, mid + 1, r, mid + 1, bh);
  pushup(i);
}
int main() {
  n = rd(), m = rd(), q = rd();
  for (int i = 1; i <= (int)q; i++) {
    int x1 = rd(), fjksdlfkasdj = rd(), x2 = rd(), fkjaskfsdfkasdlkf = rd();
    pi[x1].push_back(make_pair(fjksdlfkasdj, fkjaskfsdfkasdlkf));
    po[x2 + 1].push_back(make_pair(fjksdlfkasdj, fkjaskfsdfkasdlkf));
  }
  modify(1, 1, m, 1, 1);
  mt.insert(make_pair(0, 0));
  for (int j = 0; j <= (int)pi[1].size() - 1; j++) mt.insert(pi[1][j]);
  for (int i = 2; i <= (int)n; i++) {
    sort(pi[i].begin(), pi[i].end());
    for (int j = pi[i].size() - 1; j >= (int)0; j--) {
      int k = j;
      int bot = pi[i][k].first, top = pi[i][j].second;
      if (top < m) {
        pair<int, int> low = (*--mt.lower_bound(make_pair(top + 2, 0)));
        modify(1, 1, m, top + 1, query(1, 1, m, low.second + 1, top + 1));
      }
      j = k;
    }
    for (int j = 0; j <= (int)po[i].size() - 1; j++) mt.erase(po[i][j]);
    for (int j = 0; j <= (int)pi[i].size() - 1; j++) {
      mt.insert(pi[i][j]);
      clear(1, 1, m, pi[i][j].first, pi[i][j].second);
    }
  }
  pair<int, int> low = (*--mt.end());
  rt(query(1, 1, m, low.first + 1, m));
}
