#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long fpow(long long a, int n) {
  long long cur = a;
  long long ans = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      ans *= cur;
      ans %= mod;
    }
    cur *= cur;
    cur %= mod;
    n /= 2;
  }
  return ans;
}
int main() {
  int k, n, m;
  cin >> k >> n >> m;
  vector<int> l1(n), r1(n), l2(m), r2(m);
  for (int i = 0; i < (int)(n); i++) {
    cin >> l1[i] >> r1[i];
  }
  for (int i = 0; i < (int)(m); i++) {
    cin >> l2[i] >> r2[i];
  }
  vector<int> coords = {1, k + 1};
  for (int i = 0; i < (int)(n); i++) {
    coords.push_back(l1[i]);
    coords.push_back(r1[i] + 1);
  }
  for (int i = 0; i < (int)(m); i++) {
    coords.push_back(l2[i]);
    coords.push_back(r2[i] + 1);
  }
  sort(coords.begin(), coords.end());
  coords.resize(unique(coords.begin(), coords.end()) - coords.begin());
  vector<int> ends[coords.size()];
  for (int i = 0; i < (int)(n); i++) {
    auto en =
        lower_bound(coords.begin(), coords.end(), r1[i] + 1) - coords.begin();
    ends[en].push_back(i);
  }
  for (int i = 0; i < (int)(m); i++) {
    auto en =
        lower_bound(coords.begin(), coords.end(), r2[i] + 1) - coords.begin();
    ends[en].push_back(i + n);
  }
  long long ans = 1;
  deque<pair<int, long long> > q[2];
  for (int j = 0; j < (int)(2); j++) q[j].push_back(make_pair(0, 1ll));
  long long qs[2] = {1ll, 1ll};
  for (int i = 0; i < (int)(coords.size() - 1); i++) {
    if (i > 0) {
      long long a = qs[0];
      long long b = qs[1];
      qs[0] = (qs[0] + b) % mod;
      qs[1] = (qs[1] + a) % mod;
      q[0].back().second = (q[0].back().second + b) % mod;
      q[1].back().second = (q[1].back().second + a) % mod;
    }
    long long bg = coords[i], en = coords[i + 1];
    for (int j = 0; j < (int)(2); j++) {
      long long dp =
          (ans * ((((fpow(2, en - bg - 1) - 1) % (mod)) + (mod)) % (mod))) %
          mod;
      q[j].push_back(make_pair(bg, dp));
      qs[j] += dp;
      qs[j] %= mod;
    }
    for (int u : ends[i + 1]) {
      if (u < n) {
        while (q[1].front().first < l1[u]) {
          qs[1] = ((((qs[1] - q[1].front().second) % (mod)) + (mod)) % (mod));
          q[1].pop_front();
        }
      } else {
        u -= n;
        while (q[0].front().first < l2[u]) {
          qs[0] = ((((qs[0] - q[0].front().second) % (mod)) + (mod)) % (mod));
          q[0].pop_front();
        }
      }
    }
    ans = (qs[0] + qs[1]) % mod;
  }
  cout << ans << endl;
  return 0;
}
