#include <bits/stdc++.h>
using namespace std;
long long K(long long x, int y = 1000000007 - 2) {
  long long t = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) t = t * x % 1000000007;
  return t;
}
int k, n[2], tot, ans;
int c[2][202000], d[2][2][202000];
inline void U(int &x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
struct L {
  int l, r, type;
} a[202000], now;
int R[202000];
bool cmp(L u, L v) { return u.r < v.r; }
long long que(int *c, int x) {
  int t = 0;
  for (; x; x -= x & -x) U(t, c[x]);
  return t;
}
int add(int *c, int x, int v) {
  for (; x <= tot; x += x & -x) U(c[x], v);
}
map<int, int> mx;
int tp;
int main() {
  cin >> k >> n[0] >> n[1];
  ans = K(2, k);
  for (int t = 0, x, y; t < 2; ++t) {
    mx.clear();
    tp = 0;
    for (int i = 1; i <= n[t]; ++i) {
      scanf("%d%d", &x, &y);
      mx[y] = max(mx[y], x);
    }
    for (auto o : mx)
      if (o.second > tp) tp = o.second, a[++tot] = (L){o.second, o.first, t};
  }
  sort(a + 1, a + tot + 1, cmp);
  for (int i = 1; i <= tot; ++i) R[i] = a[i].r;
  for (int i = 1; i <= tot; ++i) {
    now = a[i];
    int p = lower_bound(R + 1, R + tot + 1, now.l) - R - 1;
    for (int j = 0; j < 2; ++j) {
      int res = 0, t;
      U(res, que(c[!j], p) * K(K(2, k - now.l + 1)) % 1000000007);
      U(res,
        (que(d[now.type][!j], i - 1) - que(d[now.type][!j], p) + 1000000007) %
            1000000007);
      if (j) U(res, K(2, now.l - 1));
      t = res * K(2, k - now.r) % 1000000007;
      U(ans, j ? 1000000007 - t : t);
      add(c[j], i, t);
      add(d[now.type][j], i, res);
    }
  }
  cout << ans << endl;
}
