#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
long long k, n, m, L1[2000005], L2[2000005], f[2000005][3], g[2000005][3], tot,
    cnt, all[2000005];
pair<long long, long long> a[2000005], b[2000005];
long long Id(long long x) {
  return lower_bound(all + 1, all + 1 + cnt, x) - all;
}
long long ksm(long long A, long long B) {
  long long res = 1;
  while (B) {
    if (B & 1) res *= A, res %= 1000000007;
    A *= A;
    A %= 1000000007;
    B >>= 1;
  }
  return res;
}
signed main() {
  k = read();
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) {
    long long x = read() - 1, y = read();
    a[i] = make_pair(x, y);
    all[++tot] = x;
    all[++tot] = y;
  }
  for (long long i = 1; i <= m; i++) {
    long long x = read() - 1, y = read();
    b[i] = make_pair(x, y);
    all[++tot] = x;
    all[++tot] = y;
  }
  all[++tot] = 0;
  all[++tot] = k;
  sort(all + 1, all + 1 + tot);
  cnt = unique(all + 1, all + 1 + tot) - all - 1;
  L1[0] = L2[0] = 1;
  for (long long i = 1; i <= n; i++) {
    L1[Id(a[i].second)] = max(L1[Id(a[i].second)], Id(a[i].first) + 1);
  }
  for (long long i = 1; i <= m; i++)
    L2[Id(b[i].second)] = max(L2[Id(b[i].second)], Id(b[i].first) + 1);
  for (long long i = 1; i <= cnt; i++)
    L1[i] = max(L1[i], L1[i - 1]), L2[i] = max(L2[i], L2[i - 1]);
  f[1][2] = g[1][2] = 1;
  for (long long i = 2; i <= cnt; i++) {
    f[i][2] = (f[i - 1][0] + f[i - 1][1] + f[i - 1][2]) *
              (ksm(2, all[i] - all[i - 1]) - 2) % 1000000007;
    f[i][1] = (g[i - 1][0] - g[L1[i] - 1][0] + 1000000007) % 1000000007 +
              (g[i - 1][2] - g[L1[i] - 1][2] + 1000000007) % 1000000007;
    f[i][0] = (g[i - 1][1] - g[L2[i] - 1][1] + 1000000007) % 1000000007 +
              (g[i - 1][2] - g[L2[i] - 1][2] + 1000000007) % 1000000007;
    g[i][2] = g[i - 1][2] + f[i][2];
    g[i][2] %= 1000000007;
    g[i][1] = g[i - 1][1] + f[i][1];
    g[i][1] %= 1000000007;
    g[i][0] = g[i - 1][0] + f[i][0];
    g[i][0] %= 1000000007;
  }
  printf("%lld\n", (f[cnt][0] + f[cnt][1] + f[cnt][2]) % 1000000007);
  return 0;
}
