#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 400005;
struct node {
  int l, r;
} a[N], b[N];
int k, n, m, p[N], rg[N][2], g[3], f[N][3], t;
int ksm(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod;
    y >>= 1;
  }
  return res;
}
int main() {
  scanf("%d%d%d", &k, &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].l, &a[i].r), p[++t] = --a[i].l, p[++t] = a[i].r;
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &b[i].l, &b[i].r), p[++t] = --b[i].l, p[++t] = b[i].r;
  p[++t] = 0;
  p[++t] = k;
  sort(p + 1, p + t + 1);
  t = unique(p + 1, p + t + 1) - p - 1;
  for (int i = 1; i <= t; i++) rg[i][0] = rg[i][1] = t + 1;
  for (int i = 1; i <= n; i++) {
    a[i].l = lower_bound(p + 1, p + t + 1, a[i].l) - p;
    a[i].r = lower_bound(p + 1, p + t + 1, a[i].r) - p;
    rg[a[i].l][0] = min(rg[a[i].l][0], a[i].r);
  }
  for (int i = 1; i <= m; i++) {
    b[i].l = lower_bound(p + 1, p + t + 1, b[i].l) - p;
    b[i].r = lower_bound(p + 1, p + t + 1, b[i].r) - p;
    rg[b[i].l][1] = min(rg[b[i].l][1], b[i].r);
  }
  for (int i = t - 1; i >= 0; i--)
    rg[i][0] = min(rg[i][0], rg[i + 1][0]),
    rg[i][1] = min(rg[i][1], rg[i + 1][1]);
  f[t][0] = f[t][1] = f[t][2] = 1;
  for (int i = t - 1; i >= 1; i--) {
    g[2] = (long long)f[i + 1][2] * (ksm(2, p[i + 1] - p[i]) - 2 + mod) % mod;
    for (int j = 0; j <= 1; j++)
      g[j] = ((long long)f[i + 1][j] - f[rg[i][j]][j] + mod) % mod;
    f[i][0] = ((long long)f[i + 1][0] + g[1] + g[2]) % mod;
    f[i][1] = ((long long)f[i + 1][1] + g[0] + g[2]) % mod;
    f[i][2] = ((long long)g[0] + g[1] + g[2]) % mod;
  }
  printf("%d\n", f[1][2]);
  return 0;
}
