#include <bits/stdc++.h>
using namespace std;
const int MN = 1000005, inf = 1000000005, mod = 1000000007;
const long long INF = 1000000000000000005LL;
bool comp1(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return (a.second > b.second);
  return (a.first < b.first);
}
long long dp[2][2][MN];
long long suma[2][2][MN];
long long wsuma[2][2][MN];
int pocz[2][MN];
int kon[2][MN];
int cur[5], wyw[MN];
long long pot(long long a, long long b) {
  if (!b) return 1LL;
  long long ret = pot(a, b >> 1);
  ret = (ret * ret) % mod;
  if (b & 1LL) ret = (ret * a) % mod;
  return ret;
}
priority_queue<pair<int, int> > Q;
int main() {
  int k, n, m;
  scanf("%d%d%d", &k, &n, &m);
  vector<pair<int, int> > N, M;
  long long ans = pot(2, k);
  for (int i = 1; i <= n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    N.push_back({a, b});
  }
  for (int i = 1; i <= m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    M.push_back({a, b});
  }
  sort((N).begin(), (N).end(), comp1);
  sort((M).begin(), (M).end(), comp1);
  int p = 0;
  for (int i = 0; i < n; ++i) {
    while (!Q.empty() && Q.top().first >= N[i].second) {
      wyw[Q.top().second] = 1;
      Q.pop();
    }
    Q.push({N[i].second, i});
  }
  for (int i = 0; i < n; ++i) {
    if (!wyw[i]) N[p++] = N[i];
    wyw[i] = 0;
  }
  while (!Q.empty()) Q.pop();
  n = p;
  p = 0;
  for (int i = 0; i < m; ++i) {
    while (!Q.empty() && Q.top().first >= M[i].second) {
      wyw[Q.top().second] = 1;
      Q.pop();
    }
    Q.push({M[i].second, i});
  }
  for (int i = 0; i < m; ++i) {
    if (!wyw[i]) M[p++] = M[i];
    wyw[i] = 0;
  }
  m = p;
  vector<pair<int, int> > ev;
  for (int i = 1; i <= n; ++i) ev.push_back({N[i - 1].second, i});
  for (int i = 1; i <= m; ++i) ev.push_back({M[i - 1].second, -i});
  sort((ev).begin(), (ev).end());
  dp[0][0][0] = suma[0][0][0] = wsuma[0][0][0] = 1LL;
  for (auto e : ev) {
    int u;
    if (e.second > 0) {
      cur[0]++;
      u = 0;
      kon[u][cur[u]] = e.first;
      pocz[u][cur[u]] = N[e.second - 1].first;
    } else {
      cur[1]++;
      u = 1;
      kon[u][cur[u]] = e.first;
      pocz[u][cur[u]] = M[-e.second - 1].first;
    }
    int idx =
        lower_bound(kon[u], kon[u] + cur[u] + 1, pocz[u][cur[u]]) - kon[u];
    dp[u][0][cur[u]] += (suma[u][1][cur[u] - 1] - suma[u][1][idx - 1] + mod);
    dp[u][1][cur[u]] += (suma[u][0][cur[u] - 1] - suma[u][0][idx - 1] + mod);
    dp[u][0][cur[u]] +=
        wsuma[u][1][idx - 1] * pot(2, pocz[u][cur[u]] - kon[u][idx - 1] - 1);
    dp[u][1][cur[u]] +=
        wsuma[u][0][idx - 1] * pot(2, pocz[u][cur[u]] - kon[u][idx - 1] - 1);
    dp[u][0][cur[u]] %= mod;
    dp[u][1][cur[u]] %= mod;
    idx =
        lower_bound(kon[u ^ 1], kon[u ^ 1] + cur[u ^ 1] + 1, pocz[u][cur[u]]) -
        kon[u ^ 1];
    dp[u][0][cur[u]] += wsuma[u ^ 1][1][idx - 1] *
                        pot(2, pocz[u][cur[u]] - kon[u ^ 1][idx - 1] - 1);
    dp[u][1][cur[u]] += wsuma[u ^ 1][0][idx - 1] *
                        pot(2, pocz[u][cur[u]] - kon[u ^ 1][idx - 1] - 1);
    dp[u][0][cur[u]] %= mod;
    dp[u][1][cur[u]] %= mod;
    suma[u][0][cur[u]] = (dp[u][0][cur[u]] + suma[u][0][cur[u] - 1]) % mod;
    suma[u][1][cur[u]] = (dp[u][1][cur[u]] + suma[u][1][cur[u] - 1]) % mod;
    wsuma[u][0][cur[u]] =
        (dp[u][0][cur[u]] + wsuma[u][0][cur[u] - 1] *
                                pot(2, kon[u][cur[u]] - kon[u][cur[u] - 1])) %
        mod;
    wsuma[u][1][cur[u]] =
        (dp[u][1][cur[u]] + wsuma[u][1][cur[u] - 1] *
                                pot(2, kon[u][cur[u]] - kon[u][cur[u] - 1])) %
        mod;
    ans += dp[u][0][cur[u]] * pot(2, k - kon[u][cur[u]]);
    ans %= mod;
    ans -= dp[u][1][cur[u]] * pot(2, k - kon[u][cur[u]]);
    ans = ((ans % mod) + mod) % mod;
  }
  ans = ((ans % mod) + mod) % mod;
  printf("%lld", ans);
}
