#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 50, mo = 1e9 + 7;
inline int gi() {
  char ch = getchar();
  int q = 0, x = 0;
  while (ch < '0' || ch > '9') q = (ch == '-' ? 1 : q), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? (-x) : x;
}
int fap(int a, int b) {
  int s = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mo)
    if (b & 1) s = 1ll * s * a % mo;
  return s;
}
struct data {
  int l, r;
  bool operator<(const data &c) const { return r < c.r; }
} a[N];
struct tree {
  int tr[N << 2], lz[N << 2];
  void pud(int x, int l, int r) {
    tr[(x << 1)] = 1ll * l * lz[x] % mo, lz[(x << 1)] = lz[x];
    tr[(x << 1 | 1)] = 1ll * r * lz[x] % mo, lz[(x << 1 | 1)] = lz[x];
    lz[x] = -1;
    return;
  }
  void upd(int x) {
    tr[x] = (tr[(x << 1)] + tr[(x << 1 | 1)]) % mo;
    return;
  }
  void mdf(int x, int l, int r, int ql, int qr, int s) {
    if (ql <= l && r <= qr) {
      tr[x] = 1ll * (r - l + 1) * s % mo, lz[x] = s;
      return;
    }
    int mid = (l + r) >> 1;
    if (~lz[x]) pud(x, mid - l + 1, r - mid);
    if (ql <= mid) mdf((x << 1), l, mid, ql, qr, s);
    if (qr > mid) mdf((x << 1 | 1), mid + 1, r, ql, qr, s);
    return upd(x);
  }
} T[2];
int s0[N], s1[N], v[N], tot, top;
int main() {
  int k = gi(), n = gi(), m = gi(), x, y, ans = 1;
  v[tot = 2] = k;
  for (int i = 1; i <= n; ++i)
    a[++top] = (data){v[tot + 1] = gi() - 1, v[tot + 2] = gi()}, tot += 2;
  for (int i = 1; i <= m; ++i)
    a[++top] = (data){v[tot + 1] = gi() - 1, v[tot + 2] = gi()}, tot += 2;
  sort(v + 1, v + tot + 1);
  tot = unique(v + 1, v + tot + 1) - v - 1;
  for (int i = 1; i <= n + m; ++i) {
    x = lower_bound(v + 1, v + tot + 1, a[i].l) - v;
    y = lower_bound(v + 1, v + tot + 1, a[i].r) - v;
    if (i <= n)
      s1[y] = max(s1[y], x);
    else
      s0[y] = max(s0[y], x);
  }
  memset(T[0].lz, -1, sizeof(T[0].lz));
  memset(T[1].lz, -1, sizeof(T[1].lz));
  for (int i = 2; i <= tot; ++i) {
    x = T[0].tr[1], y = T[1].tr[1];
    T[0].mdf(1, 1, tot, i, i, (ans + y) % mo);
    T[1].mdf(1, 1, tot, i, i, (ans + x) % mo);
    if (s1[i]) T[0].mdf(1, 1, tot, 1, s1[i] + 1, 0);
    if (s0[i]) T[1].mdf(1, 1, tot, 1, s0[i] + 1, 0);
    ans = (1ll * ans + x + y) * (fap(2, v[i] - v[i - 1]) - 2) % mo;
  }
  cout << (1ll * ans + T[0].tr[1] + T[1].tr[1] + mo) % mo;
  return 0;
}
