#include <bits/stdc++.h>
using namespace std;
const int INV2 = (1000000007 + 1) / 2;
int k, n[2];
pair<int, int> rg[234567];
int lst;
vector<tuple<int, int, int>> ev;
map<int, int> cmap;
long long dp, traw[2][1 << 18], tpos[1 << 18];
void upd(long long t[], int at, long long val) {
  at++;
  while (at < 1 << 18) {
    t[at] = (t[at] + val) % 1000000007;
    at += (at & -at);
  }
}
long long qry(long long t[], int at) {
  long long res = 0;
  at++;
  while (at) {
    res += t[at];
    at -= (at & -at);
  }
  return res % 1000000007;
}
long long qrng(long long t[], int l, int r) {
  if (r < l) return 0;
  long long res = qry(t, r);
  if (l) res = (res - qry(t, l - 1) + 1000000007) % 1000000007;
  return res;
}
long long poww(long long a, int b) {
  if (b == 0) return 1;
  long long res = poww(a, b / 2);
  res = (res * res) % 1000000007;
  if (b % 2) res = (res * a) % 1000000007;
  return res;
}
int main() {
  scanf("%d %d %d", &k, n, n + 1);
  for (int ty = (0); ty < (2); ty++) {
    lst = 1 << 30;
    for (int i = (0); i < (n[ty]); i++)
      scanf("%d %d", &rg[i].first, &rg[i].second), rg[i].first *= -1;
    sort(rg, rg + n[ty]);
    for (int i = (0); i < (n[ty]); i++)
      if (rg[i].second < lst) {
        lst = rg[i].second;
        ev.push_back({lst, ty, -rg[i].first});
      }
  }
  ev.push_back({0, -1, 0});
  ev.push_back({k + 1, 0, k + 1});
  sort(ev.begin(), ev.end());
  for (auto x : ev) {
    int end = get<0>(x);
    if (!cmap.count(end)) cmap.insert({end, cmap.size()});
  }
  for (auto x : ev) {
    int ty, st, end;
    tie(end, ty, st) = x;
    int cst = cmap.lower_bound(st)->second, cend = cmap[end];
    if (ty == -1) {
      dp = 1000000007 - 1;
    } else {
      dp = -1 * (qrng(traw[ty], cst, cend) +
                 qrng(tpos, 0, cst - 1) * poww(2, st - 1));
      dp = (dp % 1000000007 + 1000000007) % 1000000007;
    }
    if (ty != -1) upd(traw[ty], cend, dp);
    upd(tpos, cend, (dp * poww(INV2, end)) % 1000000007);
  }
  printf("%lld\n", dp);
  return 0;
}
