#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T &x, const T &y) {
  return x < y ? x : y;
}
template <typename T>
inline T qmax(const T &x, const T &y) {
  return x > y ? x : y;
}
template <typename T>
inline void getmin(T &x, const T &y) {
  if (y < x) x = y;
}
template <typename T>
inline void getmax(T &x, const T &y) {
  if (y > x) x = y;
}
inline void fileio(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int N = 2000006, mod = (int)1e9 + 7;
int a0[N], a1[N], cnt0, cnt1;
int nums[N], sz;
int ul[N], ur[N], mx0[N], mx1[N], tot0, tot1;
int k, n, m;
inline int qid(const int &x) {
  return lower_bound(nums + 1, nums + sz + 1, x) - nums;
}
inline void inc(int &x, const int &y) {
  if ((x += y) >= mod) x -= mod;
}
inline void dec(int &x, const int &y) {
  if ((x -= y) < 0) x += mod;
}
inline long long pw2(int y) {
  long long ans = 1;
  for (long long x = 2; y; y >>= 1, x = x * x % mod) {
    if (y & 1) ans = ans * x % mod;
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &k, &n, &m);
  nums[++sz] = k;
  for (register int i = (1); i <= (n + m); ++i) {
    scanf("%d%d", ul + i, ur + i);
    nums[++sz] = ul[i], nums[++sz] = ur[i];
    if (ul[i] > 1) nums[++sz] = ul[i] - 1;
    if (ur[i] > 1) nums[++sz] = ur[i] - 1;
  }
  sort(nums + 1, nums + sz + 1);
  sz = unique(nums + 1, nums + sz + 1) - nums - 1;
  for (register int i = (1); i <= (n + m); ++i) {
    int l = qid(ul[i]), r = qid(ur[i]);
    if (i <= n)
      getmax(mx1[r], l);
    else
      getmax(mx0[r], l);
  }
  a0[0] = 1;
  a0[1] = pw2(nums[1] - 1) - 1;
  a1[0] = 1;
  a1[1] = pw2(nums[1] - 1) - 1;
  tot0 = tot1 = pw2(nums[1] - 1);
  cnt0 = cnt1 = -1;
  if (mx0[1]) tot1 -= a1[cnt1 = 0];
  if (mx1[1]) tot0 -= a0[cnt0 = 0];
  for (register int i = (2); i <= (sz); ++i) {
    int len = nums[i] - nums[i - 1], dt0, dt1;
    assert(!a0[i] && !a1[i]);
    inc(a0[i - 1], tot1);
    dt0 = a0[i] = (long long)(tot0 + tot1) * (pw2(len - 1) - 1) % mod;
    inc(dt0, tot1);
    inc(a1[i - 1], tot0);
    dt1 = a1[i] = (long long)(tot0 + tot1) * (pw2(len - 1) - 1) % mod;
    inc(dt1, tot0);
    inc(tot0, dt0), inc(tot1, dt1);
    while (cnt0 + 1 < mx1[i]) dec(tot0, a0[++cnt0]);
    while (cnt1 + 1 < mx0[i]) dec(tot1, a1[++cnt1]);
  }
  printf("%d\n", (tot0 + tot1) % mod);
  return 0;
}
