#include <bits/stdc++.h>
using namespace std;
const int maxn = 400010;
inline int read() {
  int x = 0, f = 1;
  char ch = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  return x * f;
}
const int INF = 0x3f3f3f3f;
const int mo = (int)1e9 + 7;
inline int ksm(long long p, int q, int m) {
  p %= m;
  long long tmp = 1;
  for (; q; q >>= 1, p = p * p % m)
    if (q & 1) tmp = tmp * p % m;
  return tmp;
}
int K, N, M;
long long cnt0[maxn + 5], cnt1[maxn + 5];
long long oo[maxn + 5], vn;
pair<int, int> a[maxn + 5], b[maxn + 5];
int ba[maxn + 5], bb[maxn + 5];
int main() {
  scanf("%d%d%d", &K, &N, &M);
  vn = 0;
  oo[vn++] = 0;
  oo[vn++] = K;
  for (int i = 0; i < N; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  for (int i = 0; i < M; ++i) scanf("%d%d", &b[i].first, &b[i].second);
  for (int i = 0; i < N; ++i)
    a[i].first--, oo[vn++] = a[i].first, oo[vn++] = a[i].second;
  for (int i = 0; i < M; ++i)
    b[i].first--, oo[vn++] = b[i].first, oo[vn++] = b[i].second;
  sort(oo, oo + vn);
  vn = unique(oo, oo + vn) - oo;
  memset(ba, -1, sizeof(ba));
  memset(bb, -1, sizeof(bb));
  for (int i = 0; i < N; ++i) {
    a[i].first = lower_bound(oo, oo + vn, a[i].first) - oo;
    a[i].second = lower_bound(oo, oo + vn, a[i].second) - oo;
    ba[a[i].second] = max(ba[a[i].second], a[i].first);
  }
  for (int i = 0; i < M; ++i) {
    b[i].first = lower_bound(oo, oo + vn, b[i].first) - oo;
    b[i].second = lower_bound(oo, oo + vn, b[i].second) - oo;
    bb[b[i].second] = max(bb[b[i].second], b[i].first);
  }
  cnt0[0] = 1;
  int pre0 = 0, pre1 = 0;
  int sum0 = 1, sum1 = 0;
  for (int i = 0; i < vn - 1; ++i) {
    int tmp0 = sum0, tmp1 = sum1;
    (sum0 -= (cnt0[i] + cnt0[i + 1]) % mo) %= mo;
    (sum1 -= (cnt1[i] + cnt1[i + 1]) % mo) %= mo;
    (cnt0[i + 1] += (long long)(tmp0 + tmp1) *
                    (ksm(2, oo[i + 1] - oo[i] - 1, mo) - 1) % mo) %= mo;
    (cnt1[i] += tmp0) %= mo;
    (cnt1[i + 1] += (long long)(tmp0 + tmp1) *
                    (ksm(2, oo[i + 1] - oo[i] - 1, mo) - 1) % mo) %= mo;
    (cnt0[i] += tmp1) %= mo;
    (sum0 += (cnt0[i] + cnt0[i + 1]) % mo) %= mo;
    (sum1 += (cnt1[i] + cnt1[i + 1]) % mo) %= mo;
    while (pre0 <= ba[i + 1]) {
      (sum0 -= cnt0[pre0++]) %= mo;
    }
    while (pre1 <= bb[i + 1]) {
      (sum1 -= cnt1[pre1++]) %= mo;
    }
  }
  int ans = (sum0 + sum1) % mo;
  (ans += mo) %= mo;
  printf("%d\n", ans);
  return 0;
}
