#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int Minf = 0x7f7f7f7f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const long long MINF = 0x7f7f7f7f7f7f7f7fll;
const int N = 4e5 + 50;
const int mod = 1e9 + 7;
int l1[N], r1[N], l2[N], r2[N];
int p[N], tot;
int lpos0[N], lpos1[N];
long long ksm(long long n, int p) {
  long long a = 1;
  while (p) {
    if (p & 1) a = a * n % mod;
    n = n * n % mod;
    p >>= 1;
  }
  return a;
}
long long f[N][3];
long long sf[N][3];
long long S(int j, int l, int r) {
  long long ans = sf[r][j];
  ans = (ans + mod - sf[l][j]) % mod;
  return ans;
}
int main() {
  int k, n, m;
  scanf("%d%d%d", &k, &n, &m);
  for (int i = (1); i <= (n); ++i)
    scanf("%d%d", &l1[i], &r1[i]), --l1[i], p[++tot] = l1[i], p[++tot] = r1[i];
  for (int i = (1); i <= (m); ++i)
    scanf("%d%d", &l2[i], &r2[i]), --l2[i], p[++tot] = l2[i], p[++tot] = r2[i];
  p[++tot] = 0;
  p[++tot] = k;
  sort(p + 1, p + 1 + tot);
  tot = unique(p + 1, p + 1 + tot) - p - 1;
  for (int i = (1); i <= (n); ++i) {
    l1[i] = lower_bound(p + 1, p + 1 + tot, l1[i]) - p;
    r1[i] = lower_bound(p + 1, p + 1 + tot, r1[i]) - p;
    lpos0[r1[i]] = max(lpos0[r1[i]], l1[i]);
  }
  for (int i = (1); i <= (m); ++i) {
    l2[i] = lower_bound(p + 1, p + 1 + tot, l2[i]) - p;
    r2[i] = lower_bound(p + 1, p + 1 + tot, r2[i]) - p;
    lpos1[r2[i]] = max(lpos1[r2[i]], l2[i]);
  }
  for (int i = (1); i <= (tot); ++i) {
    lpos0[i] = max(lpos0[i], lpos0[i - 1]);
    lpos1[i] = max(lpos1[i], lpos1[i - 1]);
  }
  f[1][2] = 1;
  sf[1][2] = 1;
  for (int i = (2); i <= (tot); ++i) {
    assert(p[i] > p[i - 1]);
    f[i][0] = (S(1, lpos1[i], i - 1) + S(2, lpos1[i], i - 1)) % mod;
    f[i][1] = (S(0, lpos0[i], i - 1) + S(2, lpos0[i], i - 1)) % mod;
    f[i][2] = (f[i - 1][0] + f[i - 1][1] + f[i - 1][2]) % mod *
              (ksm(2, p[i] - p[i - 1]) - 2 + mod) % mod;
    for (int j = (0); j <= (2); ++j) sf[i][j] = (sf[i - 1][j] + f[i][j]) % mod;
  }
  cout << (f[tot][0] + f[tot][1] + f[tot][2]) % mod << endl;
}
