#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000007;
const int maxn = 400010;
int n, m, K, tot;
struct node {
  int l, r, k;
} p[maxn];
inline long long pm(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1) z = z * x % P;
    x = x * x % P, y >>= 1;
  }
  return z;
}
struct data {
  long long sum;
  int h, t;
  int L[maxn], R[maxn];
  long long s[maxn], v[maxn];
  void init() { h = t = L[1] = R[1] = v[1] = s[1] = sum = 1; }
  void updata(int l, int r, long long tmp) {
    if (R[t] < r) {
      t++, L[t] = R[t] = R[t - 1] + 1, s[t] = v[t] = tmp, sum = (sum + tmp) % P;
      if (R[t] < r) {
        t++, L[t] = R[t - 1] + 1, R[t] = r,
             s[t] = (pm(2, R[t] - L[t] + 1) - 1) * sum % P, v[t] = sum,
             sum = (sum + s[t]) % P;
      }
    }
    while (h <= t && R[h] <= l) sum = (sum - s[h]) % P, h++;
    if (h <= t && L[h] <= l) {
      v[h] = v[h] * pm(2, l + 1 - L[h]) % P, L[h] = l + 1,
      sum = (sum - s[h]) % P, s[h] = (pm(2, R[h] - L[h] + 1) - 1) * v[h] % P,
      sum = (sum + s[h]) % P;
    }
  }
} s[2];
bool cmp(const node &a, const node &b) { return a.r < b.r; }
int main() {
  scanf("%d%d%d", &K, &n, &m);
  int i;
  for (i = 1; i <= n; i++) scanf("%d%d", &p[i].l, &p[i].r);
  for (i = 1; i <= m; i++)
    scanf("%d%d", &p[i + n].l, &p[i + n].r), p[i + n].k = 1;
  n += m;
  sort(p + 1, p + n + 1, cmp);
  s[0].init(), s[1].init();
  for (i = 1; i <= n; i++) {
    long long a = s[0].sum, b = s[1].sum;
    if (!p[i].k)
      s[0].updata(0, p[i].r, b), s[1].updata(p[i].l, p[i].r, a);
    else
      s[0].updata(p[i].l, p[i].r, b), s[1].updata(0, p[i].r, a);
  }
  long long a = s[0].sum, b = s[1].sum;
  s[0].updata(0, K, b), s[1].updata(0, K, a);
  printf("%lld", (s[0].sum + s[1].sum + P + P) % P);
  return 0;
}
