#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100000;
const int MAXC = 4 * MAXN + 2;
const int MOD = 1000000007;
int pw(int x, int n) {
  int ret = 1;
  while (true) {
    if (n & 1) ret = (long long)ret * x % MOD;
    if ((n >>= 1) == 0) return ret;
    x = (long long)x * x % MOD;
  }
}
int len, na, nb;
int al[MAXN], ar[MAXN];
int bl[MAXN], br[MAXN];
int c[MAXC], nc;
int amn[MAXC];
int bmn[MAXC];
int delta[MAXC + 1][3];
void inc(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}
void dec(int &a, int b) {
  if ((a -= b) < 0) a += MOD;
}
void run() {
  scanf("%d%d%d", &len, &na, &nb);
  for (int i = (0); i < (na); ++i) scanf("%d%d", &al[i], &ar[i]), --al[i];
  for (int i = (0); i < (nb); ++i) scanf("%d%d", &bl[i], &br[i]), --bl[i];
  nc = 0;
  c[nc++] = 0, c[nc++] = len;
  for (int i = (0); i < (na); ++i) c[nc++] = al[i], c[nc++] = ar[i];
  for (int i = (0); i < (nb); ++i) c[nc++] = bl[i], c[nc++] = br[i];
  sort(c, c + nc);
  nc = unique(c, c + nc) - c;
  for (int i = (0); i < (na); ++i)
    al[i] = lower_bound(c, c + nc, al[i]) - c,
    ar[i] = lower_bound(c, c + nc, ar[i]) - c - 1;
  for (int i = (0); i < (nb); ++i)
    bl[i] = lower_bound(c, c + nc, bl[i]) - c,
    br[i] = lower_bound(c, c + nc, br[i]) - c - 1;
  for (int i = (0); i < (nc); ++i) amn[i] = nc - 1;
  for (int i = (0); i < (na); ++i) amn[al[i]] = min(amn[al[i]], ar[i]);
  for (int i = nc - 2; i >= 0; --i) amn[i] = min(amn[i], amn[i + 1]);
  for (int i = (0); i < (nc); ++i) bmn[i] = nc - 1;
  for (int i = (0); i < (nb); ++i) bmn[bl[i]] = min(bmn[bl[i]], br[i]);
  for (int i = nc - 2; i >= 0; --i) bmn[i] = min(bmn[i], bmn[i + 1]);
  for (int i = (0); i <= (nc); ++i)
    for (int j = (0); j < (3); ++j) delta[i][j] = 0;
  delta[0][2] = 1;
  delta[1][2] = -1;
  for (int i = (0); i < (nc); ++i)
    for (int j = (0); j < (3); ++j) {
      int cur = delta[i][j];
      inc(delta[i + 1][j], delta[i][j]);
      if (i == nc - 1) continue;
      if (cur == 0) continue;
      for (int k = (0); k < (3); ++k) {
        if (j == 0 && k == 0 || j == 1 && k == 1) continue;
        if (k == 0) {
          inc(delta[i + 1][k], cur);
          dec(delta[amn[i] + 1][k], cur);
        }
        if (k == 1) {
          inc(delta[i + 1][k], cur);
          dec(delta[bmn[i] + 1][k], cur);
        }
        if (k == 2) {
          int w = (pw(2, c[i + 1] - c[i]) + MOD - 2) % MOD;
          int v = (long long)w * cur % MOD;
          inc(delta[i + 1][k], v);
          dec(delta[i + 2][k], v);
        }
      }
    }
  int ret = 0;
  for (int j = (0); j < (3); ++j) inc(ret, delta[nc - 1][j]);
  printf("%d\n", ret);
}
int main() {
  run();
  return 0;
}
