#include <bits/stdc++.h>
const int MAXN = 5e5 + 5;
const int ha = 1e9 + 7;
int k, n, m;
std::pair<int, int> a[2][MAXN];
std::vector<int> S;
int lim[2][MAXN];
int f[2][MAXN];
inline void add(int &x, int y) {
  x += y;
  if (x >= ha) x -= ha;
}
inline int qpow(int a, int n = ha - 2) {
  int res = 1;
  while (n) {
    if (n & 1) res = 1ll * res * a % ha;
    a = 1ll * a * a % ha;
    n >>= 1;
  }
  return res;
}
int main() {
  scanf("%d%d%d", &k, &n, &m);
  S.push_back(0);
  S.push_back(k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[0][i].first, &a[0][i].second);
    --a[0][i].first;
    S.push_back(a[0][i].first);
    S.push_back(a[0][i].second);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[1][i].first, &a[1][i].second);
    --a[1][i].first;
    S.push_back(a[1][i].first);
    S.push_back(a[1][i].second);
  }
  memset(lim, -1, sizeof(lim));
  std::sort(S.begin(), S.end());
  S.erase(std::unique(S.begin(), S.end()), S.end());
  for (int i = 1; i <= n; ++i) {
    a[0][i].first =
        std::lower_bound(S.begin(), S.end(), a[0][i].first) - S.begin();
    a[0][i].second =
        std::lower_bound(S.begin(), S.end(), a[0][i].second) - S.begin();
    lim[0][a[0][i].second] = std::max(lim[0][a[0][i].second], a[0][i].first);
  }
  for (int i = 1; i <= m; ++i) {
    a[1][i].first =
        std::lower_bound(S.begin(), S.end(), a[1][i].first) - S.begin();
    a[1][i].second =
        std::lower_bound(S.begin(), S.end(), a[1][i].second) - S.begin();
    lim[1][a[1][i].second] = std::max(lim[1][a[1][i].second], a[1][i].first);
  }
  int n = S.size();
  for (int i = 0; i <= 1; ++i)
    for (int j = 1; j <= n; ++j) lim[i][j] = std::max(lim[i][j], lim[i][j - 1]);
  f[0][0] = 1;
  int sm0 = 1, tp0 = 0, sm1 = 0, tp1 = 0;
  for (int i = 0; i <= n - 2; ++i) {
    while (tp0 <= lim[1][i]) add(sm0, ha - f[0][tp0]), ++tp0;
    while (tp1 <= lim[0][i]) add(sm1, ha - f[1][tp1]), ++tp1;
    add(f[1][i], sm0);
    add(f[0][i], sm1);
    int gx = qpow(2, S[i + 1] - S[i] - 1);
    add(gx, ha - 1);
    gx = 1ll * gx * (sm0 + sm1) % ha;
    add(f[0][i + 1], gx);
    add(f[1][i + 1], gx);
    int t0 = sm0, t1 = sm1;
    add(sm0, t1);
    add(sm1, t0);
    add(sm0, gx);
    add(sm1, gx);
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i)
    if (i > lim[1][n]) add(ans, f[0][i]);
  for (int i = 0; i <= n; ++i)
    if (i > lim[0][n]) add(ans, f[1][i]);
  printf("%d\n", ans);
  return 0;
}
