#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s;
}
const int N = 1e6 + 5, mod = 1e9 + 7;
int k, n, m, cnt;
int l[N], r[N], b[N];
int p[N][2], f[N][3];
inline long long qpow(long long a, long long b) {
  long long res = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) res = res * a % mod;
  return res;
}
int main() {
  k = read(), n = read(), m = read();
  for (int i = 1; i <= n + m; i++) {
    l[i] = read() - 1, r[i] = read();
    b[++cnt] = l[i];
    b[++cnt] = r[i];
  }
  b[++cnt] = 0;
  b[++cnt] = k;
  sort(b + 1, b + cnt + 1);
  cnt = unique(b + 1, b + cnt + 1) - b - 1;
  for (int i = 1; i <= cnt; i++) p[i][0] = p[i][1] = cnt + 1;
  for (int i = 1; i <= n + m; i++) {
    l[i] = lower_bound(b + 1, b + cnt + 1, l[i]) - b;
    r[i] = lower_bound(b + 1, b + cnt + 1, r[i]) - b;
    if (i <= n)
      p[l[i]][0] = min(p[l[i]][0], r[i]);
    else
      p[l[i]][1] = min(p[l[i]][1], r[i]);
  }
  for (int i = cnt - 1; i >= 1; i--)
    for (int j = 0; j < 2; j++) p[i][j] = min(p[i][j], p[i + 1][j]);
  f[cnt][0] = f[cnt][1] = f[cnt][2] = 1;
  long long g[3];
  for (int i = cnt - 1; i >= 1; i--) {
    g[2] = f[i + 1][2] * (qpow(2, b[i + 1] - b[i]) + mod - 2) % mod;
    for (int j = 0; j < 2; j++)
      g[j] = (f[i + 1][j] - f[p[i][j]][j] + mod) % mod;
    f[i][0] = (f[i + 1][0] + g[1] + g[2]) % mod;
    f[i][1] = (f[i + 1][1] + g[0] + g[2]) % mod;
    f[i][2] = (g[0] + g[1] + g[2]) % mod;
  }
  printf("%d", f[1][2]);
  return 0;
}
