#include <bits/stdc++.h>
using namespace std;
const int MOD = 1E9 + 7;
int Add(int a, int b, int m = MOD) {
  a += b;
  if (a >= m) a -= m;
  return a;
}
int Sub(int a, int b, int m = MOD) {
  a -= b;
  if (a < 0) a += m;
  return a;
}
int AddTo(int& to, int w, int m = MOD) {
  to += w;
  if (to >= m) to -= m;
  return to;
}
int SubTo(int& to, int w, int m = MOD) {
  to -= w;
  if (to < 0) to += m;
  return to;
}
int Mult(int a, int b, int m = MOD) { return (a * 1LL * b) % m; }
int Pow(int a, long long deg, int m = MOD) {
  int res = 1 % m;
  for (; deg > 0; deg >>= 1, a = Mult(a, a, m))
    if (deg & 1) res = Mult(res, a, m);
  return res;
}
int Deg2(int how) { return Pow(2, how); }
int SDeg2(int how) { return Sub(Pow(2, how + 1), 1); }
const int MAX = 1200100;
struct SumBit {
  vector<int> arr;
  SumBit() { arr.resize(MAX); }
  void Add(int pos, int w) {
    ++pos;
    for (; pos < MAX; pos += (pos & (-pos))) AddTo(arr[pos], w);
  }
  int Get(int lo, int hi) {
    ++lo, ++hi;
    int res = 0;
    for (; hi > 0; hi -= (hi & (-hi))) AddTo(res, arr[hi]);
    for (--lo; lo > 0; lo -= (lo & (-lo))) SubTo(res, arr[lo]);
    return res;
  }
};
struct MaxBit {
  vector<int> arr;
  MaxBit() { arr.resize(MAX, -1); }
  void Add(int pos, int w) {
    ++pos;
    for (; pos < MAX; pos += (pos & (-pos))) (arr[pos]) = max((arr[pos]), (w));
  }
  int Get(int hi) {
    ++hi;
    int res = -1;
    for (; hi > 0; hi -= (hi & (-hi))) (res) = max((res), (arr[hi]));
    return res;
  }
};
int k, n, m;
vector<pair<int, int> > lr[2];
vector<int> pos, rpos;
SumBit sb[2];
MaxBit mb[2];
int main() {
  scanf("%d%d%d", &k, &n, &m);
  lr[0].resize(n);
  lr[1].resize(m);
  for (auto& e : lr[0])
    scanf("%d%d", &e.first, &e.second), --e.first, --e.second;
  for (auto& e : lr[1])
    scanf("%d%d", &e.first, &e.second), --e.first, --e.second;
  for (auto& e : lr[0])
    pos.push_back(e.first), pos.push_back(e.first - 1),
        pos.push_back(e.first + 1), pos.push_back(e.second),
        pos.push_back(e.second - 1), pos.push_back(e.second + 1);
  for (auto& e : lr[1])
    pos.push_back(e.first), pos.push_back(e.first - 1),
        pos.push_back(e.first + 1), pos.push_back(e.second),
        pos.push_back(e.second - 1), pos.push_back(e.second + 1);
  pos.push_back(0), pos.push_back(k - 1);
  sort(pos.begin(), pos.end());
  pos.erase(unique(pos.begin(), pos.end()), pos.end());
  while (pos.front() < 0) pos.erase(pos.begin());
  while (pos.back() >= k) pos.pop_back();
  rpos.resize(((int)(pos).size()));
  for (int i = 0; i < ((int)(pos).size()); ++i) rpos[i] = pos[i];
  for (auto& e : lr[0])
    e.first = lower_bound(pos.begin(), pos.end(), e.first) - pos.begin(),
    e.second = lower_bound(pos.begin(), pos.end(), e.second) - pos.begin();
  for (auto& e : lr[1])
    e.first = lower_bound(pos.begin(), pos.end(), e.first) - pos.begin(),
    e.second = lower_bound(pos.begin(), pos.end(), e.second) - pos.begin();
  for (auto& e : lr[0]) mb[0].Add(e.second, e.first);
  for (auto& e : lr[1]) mb[1].Add(e.second, e.first);
  long long dp0 = 1, dp1 = 1;
  for (auto& e : lr[0])
    if (0 == e.first && 0 == e.second) dp1 = 0;
  for (auto& e : lr[1])
    if (0 == e.first && 0 == e.second) dp0 = 0;
  sb[0].Add(0, dp0);
  sb[1].Add(0, dp1);
  for (int i = 1; i < ((int)(pos).size()); ++i) {
    int lo, hi = rpos[i];
    if (i)
      lo = rpos[i - 1] + 1;
    else
      lo = 0;
    int p = max(mb[1].Get(i), 0);
    dp0 = (p < i) ? sb[1].Get(p, i) : 0;
    if (mb[1].Get(i) == -1) dp0 = Add(dp0, 1);
    p = max(mb[0].Get(i), 0);
    dp1 = (p < i) ? sb[0].Get(p, i) : 0;
    if (mb[0].Get(i) == -1) dp1 = Add(dp1, 1);
    sb[0].Add(i, Mult(dp0, SDeg2(hi - lo)));
    sb[1].Add(i, Mult(dp1, SDeg2(hi - lo)));
    dp0 = Mult(dp0, Deg2(hi - lo));
    dp1 = Mult(dp1, Deg2(hi - lo));
  }
  cout << Add(dp0, dp1) << '\n';
  return 0;
}
