#include <bits/stdc++.h>
using namespace std;
int IN() {
  int x = 0, f = 0, ch;
  for (; (ch = getchar()) < '0' || ch > '9';) f = (ch == '-');
  for (; ch >= '0' && ch <= '9'; (ch = getchar())) x = x * 10 + ch - '0';
  return f ? -x : x;
}
int N, M, K;
vector<pair<int, int> > G1[1000005], G2[1000005], G3[1000005];
struct Nod {
  int sum, laz, Max, Cov;
} T[1000005 << 2];
void Clear(int u) {
  T[u].sum = 0;
  T[u].laz = 1;
}
void Cov(int u, int c) { T[u].Cov = T[u].Max = c; }
void Up(int u) {
  T[u].sum = (T[u << 1].sum + T[u << 1 | 1].sum) % 1000000007;
  T[u].Max = max(T[u << 1].Max, T[u << 1 | 1].Max);
}
void Down(int u) {
  if (T[u].laz) {
    Clear(u << 1);
    Clear(u << 1 | 1);
    T[u].laz = 0;
  }
  if (T[u].Cov != -1) {
    Cov(u << 1, T[u].Cov);
    Cov(u << 1 | 1, T[u].Cov);
    T[u].Cov = -1;
  }
}
void Build(int u, int l, int r) {
  T[u].Cov = -1;
  if (l == r) return;
  int Mid = (l + r) >> 1;
  Build(u << 1, l, Mid);
  Build(u << 1, Mid + 1, r);
}
void ModifyVal(int u, int l, int r, int x, int v) {
  if (l == r) {
    T[u].sum = v;
    return;
  }
  int Mid = (l + r) >> 1;
  Down(u);
  if (x <= Mid)
    ModifyVal(u << 1, l, Mid, x, v);
  else
    ModifyVal(u << 1 | 1, Mid + 1, r, x, v);
  Up(u);
}
void ModifyCov(int u, int l, int r, int x, int y, int v) {
  if (x <= l && r <= y) {
    Cov(u, v);
    return;
  }
  int Mid = (l + r) >> 1;
  Down(u);
  if (x <= Mid) ModifyCov(u << 1, l, Mid, x, y, v);
  if (y > Mid) ModifyCov(u << 1 | 1, Mid + 1, r, x, y, v);
  Up(u);
}
void ModifySum(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    Clear(u);
    return;
  }
  int Mid = (l + r) >> 1;
  Down(u);
  if (x <= Mid) ModifySum(u << 1, l, Mid, x, y);
  if (y > Mid) ModifySum(u << 1 | 1, Mid + 1, r, x, y);
  Up(u);
}
int QueryMax(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) return T[u].Max;
  int Mid = (l + r) >> 1;
  Down(u);
  if (y <= Mid) return QueryMax(u << 1, l, Mid, x, y);
  if (x > Mid) return QueryMax(u << 1 | 1, Mid + 1, r, x, y);
  return max(QueryMax(u << 1, l, Mid, x, y),
             QueryMax(u << 1 | 1, Mid + 1, r, x, y));
}
int QuerySum(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) return T[u].sum;
  int Mid = (l + r) >> 1;
  Down(u);
  if (y <= Mid) return QuerySum(u << 1, l, Mid, x, y);
  if (x > Mid) return QuerySum(u << 1 | 1, Mid + 1, r, x, y);
  return (QuerySum(u << 1, l, Mid, x, y) +
          QuerySum(u << 1 | 1, Mid + 1, r, x, y)) %
         1000000007;
}
int main(int argc, char* argv[]) {
  N = IN();
  M = IN();
  K = IN();
  for (int i = 1, lim = K; i <= lim; i++) {
    int x1 = IN(), y1 = IN(), x2 = IN(), y2 = IN();
    G1[x1].push_back(make_pair(y1, y2));
    G2[x2 + 1].push_back(make_pair(y1, y2));
    G3[x1].push_back(make_pair(y2 + 1, 0));
  }
  G3[N + 1].push_back(make_pair(M, 0));
  Build(1, 1, M);
  ModifyVal(1, 1, M, 1, 1);
  ModifyCov(1, 1, M, 2, M, M);
  for (int i = 1, lim = N + 1; i <= lim; i++) {
    for (int j = 1, lim = G3[i].size(); j <= lim; j++) {
      int x = G3[i][j - 1].first, y = QueryMax(1, 1, M, 1, x);
      if (y + 1 <= x) G3[i][j - 1].second = QuerySum(1, 1, M, y + 1, x);
    }
    for (int j = 1, lim = G2[i].size(); j <= lim; j++)
      ModifyCov(1, 1, M, G2[i][j - 1].first, G2[i][j - 1].second, 0);
    if (i == 1) ModifyCov(1, 1, M, 2, M, 0);
    for (int j = 1, lim = G3[i].size(); j <= lim; j++)
      ModifyVal(1, 1, M, G3[i][j - 1].first, G3[i][j - 1].second);
    for (int j = 1, lim = G1[i].size(); j <= lim; j++) {
      ModifyCov(1, 1, M, G1[i][j - 1].first, G1[i][j - 1].second,
                G1[i][j - 1].second);
      ModifySum(1, 1, M, G1[i][j - 1].first, G1[i][j - 1].second);
    }
  }
  printf("%d\n", G3[N + 1][0].second);
  return 0;
}
