#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long read() {
  long long x = 0, ch = getchar(), f = 0;
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - 48, ch = getchar();
  return f ? -x : x;
}
inline long long ksm(long long a, long long b) {
  long long tmp = 1;
  while (b) {
    if (b & 1) tmp = (tmp * a) % mod;
    b >>= 1, a = (a * a) % mod;
  }
  return tmp;
}
long long k, n, m, tot, p[1000010], lim[2][1000010], f[1000010][3],
    a[1000010][2], b[1000010][2];
int main() {
  k = read(), n = read(), m = read();
  for (register long long i = 1; i <= n; i++)
    a[i][0] = p[++tot] = read() - 1, a[i][1] = p[++tot] = read();
  for (register long long i = 1; i <= m; i++)
    b[i][0] = p[++tot] = read() - 1, b[i][1] = p[++tot] = read();
  p[++tot] = 0, p[++tot] = k;
  sort(p + 1, p + tot + 1);
  tot = unique(p + 1, p + tot + 1) - p - 1;
  for (register long long i = 1; i <= tot; i++)
    lim[0][i] = tot + 1, lim[1][i] = tot + 1;
  for (register long long x, i = 1; i <= n; i++)
    x = lower_bound(p + 1, p + tot + 1, a[i][0]) - p,
    lim[0][x] = ((lim[0][x]) < (lower_bound(p + 1, p + tot + 1, a[i][1]) - p)
                     ? (lim[0][x])
                     : (lower_bound(p + 1, p + tot + 1, a[i][1]) - p));
  for (register long long x, i = 1; i <= m; i++)
    x = lower_bound(p + 1, p + tot + 1, b[i][0]) - p,
    lim[1][x] = ((lim[1][x]) < (lower_bound(p + 1, p + tot + 1, b[i][1]) - p)
                     ? (lim[1][x])
                     : (lower_bound(p + 1, p + tot + 1, b[i][1]) - p));
  for (register long long i = tot - 1; i; i--)
    lim[0][i] = ((lim[0][i]) < (lim[0][i + 1]) ? (lim[0][i]) : (lim[0][i + 1])),
    lim[1][i] = ((lim[1][i]) < (lim[1][i + 1]) ? (lim[1][i]) : (lim[1][i + 1]));
  f[tot][0] = f[tot][1] = f[tot][2] = 1;
  for (register long long g0, g1, g2, i = tot - 1; i >= 1; i--) {
    g0 = (f[i + 1][1] - f[lim[0][i]][1] + mod) % mod;
    g1 = (f[i + 1][0] - f[lim[1][i]][0] + mod) % mod;
    g2 = f[i + 1][2] * (ksm(2, p[i + 1] - p[i]) - 2 + mod) % mod;
    f[i][0] = (g0 + g2 + f[i + 1][0]) % mod;
    f[i][1] = (g1 + g2 + f[i + 1][1]) % mod;
    f[i][2] = (g0 + g1 + g2) % mod;
  }
  printf("%lld", f[1][2]);
  return 0;
}
