#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 400007;
const int MOD = 1e9 + 7;
struct lT {
  bool operator<(const lT &a) const { return r < a.r; }
  int l, r;
} ln[2][MAXN];
int n, m[2], K;
long long frac[MAXN], rf[MAXN];
int dp[MAXN][2];
map<int, int> bts;
int stb[MAXN];
int len[MAXN];
void init();
void input();
void work();
int add(int x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
  return x;
}
void addv(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int dec(int x, int y) {
  x -= y;
  if (x < 0) x += MOD;
  return x;
}
void decv(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
int qpow(int a, int b) {
  long long base = a, ans = 1;
  while (b) {
    if (b & 1) (ans *= base) %= MOD;
    (base *= base) %= MOD;
    b >>= 1;
  }
  return static_cast<int>(ans);
}
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d%d", &K, &m[0], &m[1]);
  for (int j = 0; j < 2; ++j) {
    for (int i = 1; i <= m[j]; ++i) {
      scanf("%d%d", &ln[j][i].l, &ln[j][i].r);
    }
  }
}
void work() {
  for (int i = 0; i < 2; ++i) sort(ln[i] + 1, ln[i] + 1 + m[i]);
  bts[0] = 0;
  bts[1] = 0;
  bts[K] = 0;
  for (int i = 0; i < 2; ++i)
    for (int j = 1; j <= m[i]; ++j) bts[ln[i][j].l] = 0, bts[ln[i][j].r] = 0;
  n = 0;
  for (auto &x : bts) x.second = n, stb[n] = x.first, ++n;
  --n;
  for (int i = 0; i < n; ++i) len[i] = stb[i + 1] - stb[i];
  len[n] = 1;
  for (int i = 0; i < 2; ++i)
    for (int j = 1; j <= m[i]; ++j)
      ln[i][j].l = bts[ln[i][j].l], ln[i][j].r = bts[ln[i][j].r];
  int tl[2] = {0, 0};
  dp[0][0] = dp[0][1] = 1;
  int ps[2] = {1, 1};
  int ni[2] = {1, 1};
  int ts;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (; ni[j] <= m[j] && ln[j][ni[j]].r == i; ++ni[j]) {
        while (tl[j] < ln[j][ni[j]].l) decv(ps[j], dp[tl[j]][j]), ++tl[j];
      }
    }
    for (int j = 0; j < 2; ++j) dp[i][j] = ps[j ^ 1];
    ts = add(dp[i][0], dp[i][1]);
    addv(dp[i][0],
         static_cast<long long>(ts) * dec(qpow(2, len[i] - 1), 1) % MOD);
    addv(dp[i][1],
         static_cast<long long>(ts) * dec(qpow(2, len[i] - 1), 1) % MOD);
    for (int j = 0; j < 2; ++j) addv(ps[j], dp[i][j]);
  }
  cout << add(dp[n][0], dp[n][1]) << endl;
}
