#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int first = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) {
    if (ch == '-') f = -1;
  }
  for (; isdigit(ch); ch = getchar()) {
    first = first * 10 + ch - 48;
  }
  return first * f;
}
const int mxN = 4e5;
const int P = 1e9 + 7;
long long quickpow(long long first, long long second) {
  long long cur = first, ret = 1ll;
  for (int i = 0; second; i++) {
    if (second & (1ll << i)) {
      second -= (1ll << i);
      ret = ret * cur % P;
    }
    cur = cur * cur % P;
  }
  return ret;
}
int n, m, len;
vector<int> disc;
pair<int, int> a[mxN + 3], b[mxN + 3];
int la[mxN + 3], lb[mxN + 3];
long long f[mxN + 3], g[mxN + 3], h, sf, sg, pos0, pos1;
void updsum(long long &first, long long second) {
  first += first + second >= P ? second - P : second;
}
int main() {
  len = read(), n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    a[i].first = read(), a[i].second = read();
    disc.push_back(a[i].first - 1), disc.push_back(a[i].second);
  }
  for (int i = 1; i <= m; i++) {
    b[i].first = read(), b[i].second = read();
    disc.push_back(b[i].first - 1), disc.push_back(b[i].second);
  }
  disc.push_back(0), disc.push_back(len);
  sort(disc.begin(), disc.end());
  disc.erase(unique(disc.begin(), disc.end()), disc.end());
  for (int i = 1; i <= n; i++) {
    a[i].first =
        lower_bound(disc.begin(), disc.end(), a[i].first) - disc.begin(),
    a[i].second =
        lower_bound(disc.begin(), disc.end(), a[i].second) - disc.begin();
  }
  for (int i = 1; i <= m; i++) {
    b[i].first =
        lower_bound(disc.begin(), disc.end(), b[i].first) - disc.begin(),
    b[i].second =
        lower_bound(disc.begin(), disc.end(), b[i].second) - disc.begin();
  }
  for (int i = 1; i <= n; i++) {
    la[a[i].second] = max(la[a[i].second], a[i].first);
  }
  for (int i = 1; i <= m; i++) {
    lb[b[i].second] = max(lb[b[i].second], b[i].first);
  }
  h = 1ll;
  for (int i = 0; i + 1 < disc.size(); i++) {
    f[i] = (sg + h) % P;
    g[i] = (sf + h) % P;
    h = (sf + sg + h) * (quickpow(2ll, disc[i + 1] - disc[i]) - 2ll) % P;
    sf = (sf + f[i]) % P;
    sg = (sg + g[i]) % P;
    while (pos0 < la[i + 1]) {
      sf = (sf - f[pos0] + P) % P;
      pos0++;
    }
    while (pos1 < lb[i + 1]) {
      sg = (sg - g[pos1] + P) % P;
      pos1++;
    }
  }
  long long ans = (h + sf + sg) % P;
  printf("%lld\n", ans);
  return 0;
}
