#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
template <int mod>
struct modint {
  int x;
  modint(int o = 0) { x = o; }
  modint &operator=(int o) { return x = o, *this; }
  modint &operator+=(modint o) {
    return x = x + o.x >= mod ? x + o.x - mod : x + o.x, *this;
  }
  modint &operator-=(modint o) {
    return x = x - o.x < 0 ? x - o.x + mod : x - o.x, *this;
  }
  modint &operator*=(modint o) { return x = 1ll * x * o.x % mod, *this; }
  modint &operator^=(int b) {
    modint a = *this, c = 1;
    for (; b; b >>= 1, a *= a)
      if (b & 1) c *= a;
    return x = c.x, *this;
  }
  modint &operator/=(modint o) { return *this *= o ^= mod - 2; }
  modint &operator+=(int o) {
    return x = x + o >= mod ? x + o - mod : x + o, *this;
  }
  modint &operator-=(int o) {
    return x = x - o < 0 ? x - o + mod : x - o, *this;
  }
  modint &operator*=(int o) { return x = 1ll * x * o % mod, *this; }
  modint &operator/=(int o) { return *this *= ((modint(o)) ^= mod - 2); }
  template <class I>
  friend modint operator+(modint a, I b) {
    return a += b;
  }
  template <class I>
  friend modint operator-(modint a, I b) {
    return a -= b;
  }
  template <class I>
  friend modint operator*(modint a, I b) {
    return a *= b;
  }
  template <class I>
  friend modint operator/(modint a, I b) {
    return a /= b;
  }
  friend modint operator^(modint a, int b) { return a ^= b; }
  friend bool operator==(modint a, int b) { return a.x == b; }
  friend bool operator!=(modint a, int b) { return a.x != b; }
  bool operator!() { return !x; }
  modint operator-() { return x ? mod - x : 0; }
};
template <int P>
ostream &operator<<(ostream &out, modint<P> &x) {
  cout << x.x;
}
modint<1000000007> val[1000005 << 2], tag[1000005 << 2];
inline void pushup(int p) { val[p] = val[p << 1] + val[p << 1 | 1]; }
inline void pusht(int p, int len, modint<1000000007> v) {
  tag[p] = v, val[p] = v * len;
}
inline void pushdown(int p, int l, int r) {
  if (tag[p] == -1) return;
  int mid = l + r >> 1;
  pusht(p << 1, mid - l + 1, tag[p]);
  pusht(p << 1 | 1, r - mid, tag[p]);
  tag[p] = -1;
}
void modify(int p, int l, int r, int nl, int nr, modint<1000000007> v) {
  if (l >= nl && r <= nr) return pusht(p, r - l + 1, v);
  int mid = l + r >> 1;
  pushdown(p, l, r);
  if (nl <= mid) modify(p << 1, l, mid, nl, nr, v);
  if (nr > mid) modify(p << 1 | 1, mid + 1, r, nl, nr, v);
  pushup(p);
}
void add(int p, int l, int r, int x, modint<1000000007> v) {
  if (l == r) return val[p] += v, void();
  int mid = l + r >> 1;
  pushdown(p, l, r);
  if (x <= mid)
    add(p << 1, l, mid, x, v);
  else
    add(p << 1 | 1, mid + 1, r, x, v);
  pushup(p);
}
modint<1000000007> ask(int p, int l, int r, int ql, int qr) {
  if (ql > qr) return 0;
  if (l >= ql && r <= qr) return val[p];
  int mid = l + r >> 1;
  modint<1000000007> res = 0;
  pushdown(p, l, r);
  if (ql <= mid) res += ask(p << 1, l, mid, ql, qr);
  if (qr > mid) res += ask(p << 1 | 1, mid + 1, r, ql, qr);
  return res;
}
int n, m, k, cnt;
multiset<int> s;
struct node {
  int x, _____, y2, op;
  bool operator<(const node &b) const {
    if (x == b.x) return op == b.op ? _____ > b._____ : op > b.op;
    return x < b.x;
  }
} a[1000005];
signed main() {
  n = read(), m = read(), k = read();
  for (register int i = (1); i <= (k); ++i) {
    int x1 = read(), _____ = read(), x2 = read(), y2 = read();
    a[++cnt] = (node){x1, _____, y2, 1};
    a[++cnt] = (node){x2 + 1, _____, y2, -1};
  }
  memset(tag, -1, sizeof tag);
  sort(a + 1, a + cnt + 1);
  modify(1, 1, m, 1, 1, 1);
  int p = 1;
  s.insert(0), s.insert(m + 1);
  while (p <= cnt && a[p].x == 1) s.insert(a[p]._____), s.insert(a[p].y2), ++p;
  while (p <= cnt && a[p].x <= n) {
    if (a[p].op == -1) {
      s.erase(s.find(a[p]._____));
      s.erase(s.find(a[p].y2));
    } else {
      multiset<int>::iterator it = s.upper_bound(a[p].y2);
      it--;
      modint<1000000007> v = ask(1, 1, m, (*it) + 1, a[p].y2);
      it = s.upper_bound(a[p].y2);
      if ((*it) != a[p].y2 + 1) add(1, 1, m, a[p].y2 + 1, v);
      modify(1, 1, m, a[p]._____, a[p].y2, 0);
      s.insert(a[p]._____), s.insert(a[p].y2);
    }
    p++;
  }
  multiset<int>::iterator it = s.lower_bound(m);
  it--;
  cout << ask(1, 1, m, (*it) + 1, m).x;
  return 0;
}
