#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long b) {
  if (!b) return 1;
  long long ns = ksm(a, b >> 1);
  ns = ns * ns % 1000000007;
  if (b & 1) ns = ns * a % 1000000007;
  return ns;
}
struct bit {
  int lb(int x) { return x & -x; }
  int d[200010];
  void upd(int pl, int num) {
    while (pl < 200010) d[pl] = (d[pl] + num) % 1000000007, pl += lb(pl);
  }
  int q(int pl) {
    int ans = 0;
    while (pl) {
      ans = (ans + d[pl]) % 1000000007, pl -= lb(pl);
    }
    return ans;
  }
  int q(int l, int r) { return (q(r) - q(l - 1)) % 1000000007; }
} bb[3];
struct th {
  int l, r, tp;
  th() {}
  th(int a, int b, int c) { l = a, r = b, tp = c; }
  bool operator<(const th &s) const { return l < s.l; }
} p[200010];
long long dp[200010];
int k, n, m;
const int bk2 = (1000000007 + 1) / 2;
int main() {
  cin >> k >> n >> m;
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    p[i] = th(l, r, 0);
  }
  for (int i = n + 1; i <= n + m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    p[i] = th(l, r, 1);
  }
  sort(p + 1, p + n + m + 1);
  long long ans = 0;
  int mn[2] = {k + 1, k + 1};
  for (int i = n + m; i >= 1; i--) {
    dp[i] = -ksm(2, k - p[i].r);
    int l = i, r = n + m;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (p[mid + 1].l <= p[i].r)
        l = mid + 1;
      else
        r = mid;
    }
    dp[i] += -bb[p[i].tp].q(1, l);
    dp[i] += ksm(bk2, p[i].r) * -bb[2].q(l + 1, n + m);
    dp[i] %= 1000000007;
    if (p[i].r >= mn[p[i].tp]) dp[i] = 0;
    mn[p[i].tp] = min(mn[p[i].tp], p[i].r);
    bb[p[i].tp].upd(i, dp[i]);
    bb[2].upd(i, dp[i] * ksm(2, p[i].l - 1) % 1000000007);
    ans += dp[i] * ksm(2, p[i].l - 1), ans %= 1000000007;
  }
  ans += ksm(2, k), ans %= 1000000007;
  if (ans < 0) ans += 1000000007;
  cout << ans << endl;
  return 0;
}
