#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const int mod = 1e9 + 7;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}
int k, n, m;
int l[N], r[N];
int L[N], R[N];
int hig[N][2];
int p[N], tot;
int f[N][3];
int sumf[N][3];
int Qpow(int base, int ind) {
  int res = 1;
  while (ind) {
    if (ind & 1) res = 1ll * res * base % mod;
    base = 1ll * base * base % mod;
    ind >>= 1;
  }
  return res;
}
int main() {
  read(k), read(n), read(m);
  for (int i = 1; i <= n; i++) read(l[i]), read(r[i]), l[i]--;
  for (int i = 1; i <= m; i++) read(L[i]), read(R[i]), L[i]--;
  for (int i = 1; i <= n; i++) p[++tot] = l[i], p[++tot] = r[i];
  for (int i = 1; i <= m; i++) p[++tot] = L[i], p[++tot] = R[i];
  p[++tot] = 0, p[++tot] = k;
  sort(p + 1, p + tot + 1);
  tot = unique(p + 1, p + tot + 1) - p - 1;
  for (int i = 1; i <= n; i++) {
    l[i] = lower_bound(p + 1, p + tot + 1, l[i]) - p;
    r[i] = lower_bound(p + 1, p + tot + 1, r[i]) - p;
    hig[r[i]][0] = max(hig[r[i]][0], l[i]);
  }
  for (int i = 1; i <= m; i++) {
    L[i] = lower_bound(p + 1, p + tot + 1, L[i]) - p;
    R[i] = lower_bound(p + 1, p + tot + 1, R[i]) - p;
    hig[R[i]][1] = max(hig[R[i]][1], L[i]);
  }
  for (int i = 2; i <= tot; i++)
    for (int j = 0; j <= 1; j++) hig[i][j] = max(hig[i][j], hig[i - 1][j]);
  f[1][2] = 1;
  sumf[1][2] = 1;
  for (int i = 2; i <= tot; i++) {
    f[i][0] = ((sumf[i - 1][1] - sumf[hig[i][0]][1] + mod) % mod +
               (sumf[i - 1][2] - sumf[hig[i][0]][2] + mod) % mod) %
              mod;
    f[i][1] = ((sumf[i - 1][0] - sumf[hig[i][1]][0] + mod) % mod +
               (sumf[i - 1][2] - sumf[hig[i][1]][2] + mod) % mod) %
              mod;
    f[i][2] = 1ll * ((f[i - 1][0] + f[i - 1][1]) % mod + f[i - 1][2]) % mod *
              (Qpow(2, p[i] - p[i - 1]) - 2 + mod) % mod;
    sumf[i][0] = (sumf[i - 1][0] + f[i][0]) % mod;
    sumf[i][1] = (sumf[i - 1][1] + f[i][1]) % mod;
    sumf[i][2] = (sumf[i - 1][2] + f[i][2]) % mod;
  }
  printf("%d\n", ((f[tot][0] + f[tot][1]) % mod + f[tot][2]) % mod);
  return 0;
}
