#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const int INF = 2139062143;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int mod = 1e9 + 7;
const int N = 4e5 + 7;
struct Node {
  int l, r;
} a[N], b[N];
int k, n, m, cnt, num, tmp[N * 4], mx[2][N], f[2][N];
inline int qpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return ret;
}
signed main() {
  read(k);
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    read(a[i].l);
    read(a[i].r);
    a[i].l--;
    tmp[++cnt] = a[i].l;
    tmp[++cnt] = a[i].r;
  }
  for (int i = 1; i <= m; i++) {
    read(b[i].l);
    read(b[i].r);
    b[i].l--;
    tmp[++cnt] = b[i].l;
    tmp[++cnt] = b[i].r;
  }
  tmp[++cnt] = 0;
  tmp[++cnt] = k;
  sort(tmp + 1, tmp + cnt + 1);
  num = unique(tmp + 1, tmp + cnt + 1) - tmp - 1;
  for (int i = 1; i <= n; i++) {
    a[i].l = lower_bound(tmp + 1, tmp + num + 1, a[i].l) - tmp;
    a[i].r = lower_bound(tmp + 1, tmp + num + 1, a[i].r) - tmp;
    chkmax(mx[0][a[i].r], a[i].l);
  }
  for (int i = 1; i <= m; i++) {
    b[i].l = lower_bound(tmp + 1, tmp + num + 1, b[i].l) - tmp;
    b[i].r = lower_bound(tmp + 1, tmp + num + 1, b[i].r) - tmp;
    chkmax(mx[1][b[i].r], b[i].l);
  }
  f[0][1] = 1;
  f[1][1] = 0;
  int s = 1, t = 0, pos1 = 1, pos2 = 1;
  for (int i = 2; i <= num; i++) {
    int cnt = qpow(2, tmp[i] - tmp[i - 1] - 1);
    cnt = (cnt - 1 + mod) % mod;
    int tmp0 = s, tmp1 = t;
    f[0][i - 1] = (f[0][i - 1] + t) % mod;
    f[1][i - 1] = (f[1][i - 1] + s) % mod;
    f[0][i] = (f[0][i] + 1ll * (s + t) % mod * cnt % mod) % mod;
    f[1][i] = (f[1][i] + 1ll * (s + t) % mod * cnt % mod) % mod;
    s = (tmp0 % mod + tmp1 % mod + 1ll * (tmp0 + tmp1) % mod * cnt % mod) % mod;
    t = (tmp1 % mod + tmp0 % mod + 1ll * (tmp0 + tmp1) % mod * cnt % mod) % mod;
    while (pos1 <= mx[0][i]) s = (s - f[0][pos1++] + mod) % mod;
    while (pos2 <= mx[1][i]) t = (t - f[1][pos2++] + mod) % mod;
  }
  printf("%lld\n", 1ll * (s + t) % mod);
  return 0;
}
