#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int clean(vector<pair<int, int> > &I) {
  for (int i = 0; i < (int)I.size(); i++) {
    swap(I[i].first, I[i].second);
    I[i].second *= -1;
  }
  sort(begin(I), end(I));
  for (int i = 0; i < (int)I.size(); i++) {
    I[i].second *= -1;
    swap(I[i].first, I[i].second);
  }
  vector<pair<int, int> > I_nw;
  int lastb = -1;
  for (int i = 0; i < (int)I.size(); i++) {
    if (lastb < I[i].first) I_nw.push_back(I[i]);
    lastb = max(lastb, I[i].first);
  }
  I = I_nw;
  return I_nw.size();
}
long long pw(long long a, long long e, long long mod) {
  if (e <= 0) return 1;
  long long x = pw(a, e / 2, mod);
  x = (x * x) % mod;
  if (e % 2) x = (x * a) % mod;
  return x;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int K, N[2];
  cin >> K >> N[0] >> N[1];
  vector<pair<int, int> > I[2];
  map<int, int> M;
  M[0] = M[K] = 0;
  for (int k = 0; k < 2; k++) {
    I[k].resize(N[k]);
    for (int i = 0; i < N[k]; i++) {
      cin >> I[k][i].first >> I[k][i].second;
      I[k][i].first--;
    }
    N[k] = clean(I[k]);
    for (int i = 0; i < N[k]; i++) M[I[k][i].first] = M[I[k][i].second] = 0;
  }
  int m = 0, last = 0;
  vector<int> len;
  vector<long long> cnt;
  for (auto it = M.begin(); it != M.end(); it++) {
    it->second = m++;
    if (it->first != last) len.push_back(it->first - last);
    last = it->first;
  }
  int L = len.size();
  cnt.resize(L);
  for (int i = 0; i < L; i++) cnt[i] = (pw(2, len[i], mod) + mod - 2) % mod;
  for (int k = 0; k < 2; k++)
    for (int i = 0; i < N[k]; i++) {
      I[k][i].first = M[I[k][i].first];
      I[k][i].second = M[I[k][i].second];
    }
  vector<long long> ans[3];
  for (int k = 0; k < 3; k++) ans[k].resize(L + 1, 0);
  ans[2][0] = 1;
  vector<long long> sum_ans[3];
  for (int k = 0; k < 3; k++) sum_ans[k].resize(L + 1, 0);
  int pos[2] = {0, 0}, last_st[2] = {-1, -1};
  for (int i = 0; i < L; i++) {
    for (int k = 0; k < 3; k++)
      sum_ans[k][i + 1] = (sum_ans[k][i] + ans[k][i]) % mod;
    ans[2][i + 1] = (ans[0][i] + ans[1][i] + ans[2][i]) * cnt[i] % mod;
    for (int k = 0; k < 2; k++) {
      while (pos[1 - k] < N[1 - k] && I[1 - k][pos[1 - k]].second <= i + 1) {
        last_st[1 - k] = I[1 - k][pos[1 - k]].first;
        pos[1 - k]++;
      }
      ans[k][i + 1] =
          (sum_ans[2][i + 1] - sum_ans[2][last_st[1 - k] + 1] +
           sum_ans[1 - k][i + 1] - sum_ans[1 - k][last_st[1 - k] + 1]) %
          mod;
    }
  }
  long long ansF = (ans[0][L] + ans[1][L] + ans[2][L]) % mod;
  if (ansF < 0) ansF += mod;
  cout << ansF << "\n";
  return 0;
}
