#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
void add(int64_t& a, int64_t b) { a = (a + b) % MOD; }
void mul(int64_t& a, int64_t b) { a = a * b % MOD; }
template <typename T>
struct BIT {
  int n;
  vector<T> dat;
  BIT(int n = 0) { initialize(n); }
  void initialize(int nin) {
    n = nin;
    dat.resize(n, 0);
  }
  T sum(int i) {
    T s = 0;
    while (i >= 0) {
      add(s, dat[i]);
      i = (i & (i + 1)) - 1;
    }
    return s;
  }
  T sum_between(int i, int j) { return (sum(j) - sum(i - 1) + MOD) % MOD; }
  void plus(int i, T x) {
    while (i < n) {
      add(dat[i], x);
      i |= i + 1;
    }
  }
};
int64_t power_mod(int64_t num, int64_t power) {
  int64_t prod = 1;
  num %= MOD;
  while (power > 0) {
    if (power & 1) prod = prod * num % MOD;
    num = num * num % MOD;
    power >>= 1;
  }
  return prod;
}
int main() {
  int K, N[2];
  cin >> K >> N[0] >> N[1];
  map<int, int> mp;
  mp[0] = mp[K] = 0;
  map<int, int> tmp[2];
  for (int k = 0; k < 2; k++)
    for (int i = 0; i < N[k]; i++) {
      int l, r;
      cin >> l >> r;
      tmp[k][r] = max(tmp[k][r], l - 1);
      mp[l - 1] = mp[r] = 0;
    }
  int sz = 0;
  vector<int> cmp;
  for (auto p : mp) {
    mp[p.first] = sz++;
    cmp.push_back(p.first);
  }
  vector<vector<int>> cond(2, vector<int>(sz));
  for (int k = 0; k < 2; k++)
    for (auto& p : tmp[k]) cond[k][mp[p.first]] = mp[p.second] + 1;
  BIT<int64_t> dp[2];
  for (int k = 0; k < 2; k++) {
    dp[k].initialize(sz);
  }
  dp[0].plus(0, 1);
  int64_t bef = 0;
  int l0 = 0, l1 = 0;
  for (int i = 1; i < sz; i++) {
    int len = cmp[i] - cmp[i - 1];
    int64_t mix = (power_mod(2, len) + MOD - 2) % MOD;
    int s0 = cond[0][i], s1 = cond[1][i];
    int64_t mixed = mix *
                    (dp[0].sum_between(l0, i - 1) +
                     dp[1].sum_between(l1, i - 1) - bef + MOD) %
                    MOD;
    for (int k = 0; k < 2; k++) {
      dp[k].plus(i, mixed);
    }
    int64_t a0 = dp[1].sum_between(l1, i - 1) - bef + MOD;
    int64_t a1 = dp[0].sum_between(l0, i - 1) - bef + MOD;
    if (s1 <= i - 1) dp[0].plus(i - 1, a0);
    if (s0 <= i - 1) dp[1].plus(i - 1, a1);
    l0 = max(l0, s1);
    l1 = max(l1, s0);
    bef = mixed;
  }
  int64_t ans = (MOD - bef + dp[0].sum_between(l0, sz - 1) +
                 dp[1].sum_between(l1, sz - 1)) %
                MOD;
  cout << ans << endl;
  return 0;
}
