#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const int MOD = 1e9 + 7;
int l[N << 1], r[N << 1];
int x[N << 2];
vector<int> V[N << 2];
int modExp(int a, int n, int p) {
  int ret = 1;
  for (; n; n >>= 1, a = 1LL * a * a % p)
    if (n & 1) ret = 1LL * ret * a % p;
  return ret;
}
int main() {
  int k, n, m;
  scanf("%d%d%d", &k, &n, &m);
  int xn = 0;
  x[xn++] = 1, x[xn++] = k + 1;
  for (int i = 1; i <= n + m; i++) {
    scanf("%d%d", &l[i], &r[i]);
    x[xn++] = l[i], x[xn++] = r[i] + 1;
  }
  sort(x, x + xn);
  xn = unique(x, x + xn) - x;
  for (int i = 1; i <= n + m; i++) {
    l[i] = lower_bound(x, x + xn, l[i]) - x;
    r[i] = lower_bound(x, x + xn, r[i] + 1) - x - 1;
    V[r[i]].push_back(i);
  }
  set<pair<int, int> > S[2];
  int ans[4] = {0};
  for (int i = 0; i < xn - 1; i++) {
    int seen[2] = {-1, -1};
    for (int u : V[i]) seen[u > n] = max(seen[u > n], l[u]);
    int ways = (modExp(2, x[i + 1] - x[i], MOD) + MOD - 2) % MOD;
    if (i == 0) {
      for (int j = 0; j < 2; j++) {
        if (seen[j] < 0) S[!j].insert(make_pair(-1, 1)), ans[!j]++, ans[2]++;
      }
      ans[3] = ways;
    } else {
      ways = 1LL * ways * (ans[2] + ans[3]) % MOD;
      int _ans[2] = {(ans[0] + ans[3]) % MOD, (ans[1] + ans[3]) % MOD};
      for (int j = 0; j < 2; j++) {
        while (!S[j].empty()) {
          auto it = S[j].begin();
          if (seen[!j] > it->first) {
            ans[j] = (ans[j] + MOD - it->second) % MOD;
            ans[2] = (ans[2] + MOD - it->second) % MOD;
            S[j].erase(it);
          } else {
            break;
          }
        }
      }
      for (int j = 0; j < 2; j++) {
        if (seen[j] < i) {
          S[!j].insert(make_pair(i - 1, _ans[j]));
          ans[!j] = (ans[!j] + _ans[j]) % MOD;
          ans[2] = (ans[2] + _ans[j]) % MOD;
        }
      }
      ans[3] = ways;
    }
  }
  cout << (ans[2] + ans[3]) % MOD << endl;
  return 0;
}
