#include <bits/stdc++.h>
using namespace std;
int q, n, m, i, a[100050 << 2], t, jb1[100050 << 2], jb2[100050 << 2],
    c[100050 << 2], tp;
struct lwn {
  int l, r;
  bool operator<(const lwn &jb) const { return r < jb.r; }
} b[2][100050];
struct matrix {
  int x[6][6];
  matrix operator*(const matrix &jb) const {
    matrix cll;
    for (int ii = 0; ii < 6; ii++)
      for (int jj = 0; jj < 6; jj++) cll.x[ii][jj] = 0;
    for (int ii = 0; ii < 6; ii++)
      for (int kk = 0; kk < 6; kk++)
        for (int jj = 0; jj < 6; jj++)
          cll.x[ii][jj] =
              (1LL * x[ii][kk] * jb.x[kk][jj] + cll.x[ii][jj]) % 1000000007;
    return cll;
  }
} pw[40];
struct vt {
  int x[6];
  vt operator*(const matrix &jb) const {
    vt cll;
    for (int kk = 0; kk < 6; kk++) cll.x[kk] = 0;
    for (int kk = 0; kk < 6; kk++)
      for (int jj = 0; jj < 6; jj++)
        cll.x[jj] = (1LL * x[kk] * jb.x[kk][jj] + cll.x[jj]) % 1000000007;
    return cll;
  }
} f[100050 << 2];
int main() {
  scanf("%d%d%d", &q, &n, &m);
  a[++t] = q;
  for (i = 1; i <= n; i++)
    scanf("%d%d", &b[0][i].l, &b[0][i].r), b[0][i].l--, a[++t] = b[0][i].l,
                                                        a[++t] = b[0][i].r;
  for (i = 1; i <= m; i++)
    scanf("%d%d", &b[1][i].l, &b[1][i].r), b[1][i].l--, a[++t] = b[1][i].l,
                                                        a[++t] = b[1][i].r;
  sort(a + 1, a + t + 1);
  for (i = 1; i <= t; i++)
    if (a[i] != a[i - 1]) c[++tp] = a[i];
  t = tp;
  for (i = 1; i <= t; i++) a[i] = c[i];
  sort(b[0] + 1, b[0] + n + 1);
  sort(b[1] + 1, b[1] + m + 1);
  f[0].x[0] = f[0].x[1] = f[0].x[2] = f[0].x[3] = 1;
  int mx1 = -1, mx2 = -1;
  pw[0].x[3][0] = pw[0].x[2][1] = pw[0].x[2][2] = pw[0].x[3][2] =
      pw[0].x[2][3] = pw[0].x[3][3] = pw[0].x[4][4] = pw[0].x[5][5] = 1;
  pw[0].x[5][0] = pw[0].x[4][1] = pw[0].x[5][2] = pw[0].x[4][3] = -1;
  for (i = 1; i <= 30; i++) pw[i] = pw[i - 1] * pw[i - 1];
  for (i = 1; i <= t; i++) jb1[i] = jb2[i] = -1;
  for (i = 1; i <= n; i++) {
    int ll = lower_bound(a, a + t + 1, b[0][i].l) - a,
        rr = lower_bound(a, a + t + 1, b[0][i].r) - a;
    jb1[rr] = max(jb1[rr], ll);
  }
  for (i = 1; i <= m; i++) {
    int ll = lower_bound(a, a + t + 1, b[1][i].l) - a,
        rr = lower_bound(a, a + t + 1, b[1][i].r) - a;
    jb2[rr] = max(jb2[rr], ll);
  }
  for (i = 2; i <= t; i++)
    jb1[i] = max(jb1[i], jb1[i - 1]), jb2[i] = max(jb2[i], jb2[i - 1]);
  for (i = 1; i <= t; i++) {
    vt ret = f[i - 1];
    int zhi = a[i] - a[i - 1] - 1;
    for (int ii = 0; ii <= 30; ii++)
      if (zhi & (1 << ii)) ret = ret * pw[ii];
    if (jb1[i] != -1) ret.x[5] = f[jb1[i]].x[3];
    if (jb2[i] != -1) ret.x[4] = f[jb2[i]].x[2];
    f[i] = ret * pw[0];
  }
  int ans = (f[t].x[0] + f[t].x[1]) % 1000000007;
  ans = (ans + 1000000007) % 1000000007;
  printf("%d\n", ans);
  return 0;
}
