#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int n, m, K;
const int mod = 1e9 + 7;
void fix(int &x) {
  x -= mod;
  x += x >> 31 & mod;
}
struct Seg {
  bool cle[4000005];
  int sum[4000005];
  void pushup(int x) { fix(sum[x] = sum[x << 1] + sum[x << 1 | 1]); }
  void Clean(int x) {
    cle[x] = 1;
    sum[x] = 0;
  }
  void pushdown(int x) {
    if (cle[x]) Clean(x << 1), Clean(x << 1 | 1);
    cle[x] = 0;
  }
  void Cels(int x, int l, int r, int ql, int qr) {
    int mid = (l + r) >> 1;
    if (ql <= l && r <= qr) return Clean(x);
    pushdown(x);
    if (ql <= mid) Cels(x << 1, l, mid, ql, qr);
    if (mid < qr) Cels(x << 1 | 1, mid + 1, r, ql, qr);
    pushup(x);
  }
  void Modify(int x, int l, int r, int pos, int v) {
    if (l == r) return fix(sum[x] += v);
    pushdown(x);
    int mid = (l + r) >> 1;
    (pos <= mid) ? Modify(x << 1, l, mid, pos, v)
                 : Modify(x << 1 | 1, mid + 1, r, pos, v);
    pushup(x);
  }
  void Modify(int pos, int v) { return Modify(1, 1, m, pos, v); }
  int Query(int x, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return sum[x];
    pushdown(x);
    int mid = (l + r) >> 1, ans = 0;
    if (ql <= mid) ans = Query(x << 1, l, mid, ql, qr);
    if (mid < qr) fix(ans += Query(x << 1 | 1, mid + 1, r, ql, qr));
    return ans;
  }
  int ask(int l, int r) { return (l > r) ? 0 : Query(1, 1, m, l, r); }
} T;
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
struct ivar {
  int x, y1, y2, tp;
} t[4000005];
int main() {
  n = read(), m = read(), K = read();
  int cnt = 0;
  for (int i = 1; i <= K; i++) {
    int x_1 = read(), y_1 = read(), x_2 = read(), y_2 = read();
    t[++cnt] = (ivar){x_1, y_1, y_2, 0};
    t[++cnt] = (ivar){x_2 + 1, y_1, y_2, 1};
  }
  sort(t + 1, t + cnt + 1,
       [](ivar A, ivar B) { return A.x != B.x ? A.x < B.x : A.y1 > B.y1; });
  T.Modify(1, 1);
  int p = 1;
  for (int i = p; t[i].x == 1; p = ++i) s.insert(make_pair(t[i].y1, t[i].y2));
  s.insert(make_pair(0, 0));
  for (int i = 2; i <= n; i++) {
    for (int j = p; t[j].x == i; ++j)
      if (t[j].tp == 0)
        if (t[j].y2 < m) {
          pair<int, int> loc = *--s.lower_bound(make_pair(t[j].y2 + 2, 0));
          int tmp = T.ask(loc.second + 1, t[j].y2);
          if (tmp) T.Modify(t[j].y2 + 1, tmp);
        }
    for (int j = p; t[j].x == i; ++j)
      if (t[j].tp == 1) s.erase(make_pair(t[j].y1, t[j].y2));
    for (int j = p; t[j].x == i; p = ++j)
      if (t[j].tp == 0)
        s.insert(make_pair(t[j].y1, t[j].y2)),
            T.Cels(1, 1, m, t[j].y1, t[j].y2);
  }
  pair<int, int> loc = *--s.end();
  cout << T.ask(loc.second + 1, m) << '\n';
  return 0;
}
