#include <bits/stdc++.h>
using namespace std;
long long pow_mod(long long x, int k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = ans * x % 1000000007;
    x = x * x % 1000000007;
    k >>= 1;
  }
  return ans;
}
struct SGT {
  int sumv[1600000];
  bool clv[1600000];
  inline void pushdown(int o) {
    if (clv[o]) {
      clv[o * 2] |= clv[o];
      sumv[o * 2] = 0;
      clv[o * 2 + 1] |= clv[o];
      sumv[o * 2 + 1] = 0;
      clv[o] = 0;
    }
  }
  void update(int l, int r, int o, int p, int q) {
    if (l == r)
      sumv[o] = q;
    else {
      pushdown(o);
      int m = ((l + r) >> 1);
      if (m >= p)
        update(l, m, o * 2, p, q);
      else
        update(m + 1, r, o * 2 + 1, p, q);
      sumv[o] = (sumv[o * 2] + sumv[o * 2 + 1]) % 1000000007;
    }
  }
  void clear(int l, int r, int o, int lx, int rx) {
    if (l >= lx && r <= rx) {
      clv[o] = 1;
      sumv[o] = 0;
    } else {
      pushdown(o);
      int m = ((l + r) >> 1);
      if (m >= lx) clear(l, m, o * 2, lx, rx);
      if (m < rx) clear(m + 1, r, o * 2 + 1, lx, rx);
      sumv[o] = (sumv[o * 2] + sumv[o * 2 + 1]) % 1000000007;
    }
  }
  int query() { return sumv[1]; }
} tr1, tr2;
int num[400005];
int l1[100005], r1[100005], l2[100005], r2[100005];
int max1[400005], max2[400005];
int main() {
  int k, n, m;
  scanf("%d%d%d", &k, &n, &m);
  int cnt = 0;
  num[++cnt] = 0;
  num[++cnt] = k;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    l1[i] = x - 1;
    r1[i] = y;
    num[++cnt] = l1[i];
    num[++cnt] = r1[i];
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    l2[i] = x - 1;
    r2[i] = y;
    num[++cnt] = l2[i];
    num[++cnt] = r2[i];
  }
  sort(num + 1, num + cnt + 1);
  cnt = unique(num + 1, num + cnt + 1) - num - 1;
  for (int i = 1; i <= n; i++) {
    l1[i] = lower_bound(num + 1, num + cnt + 1, l1[i]) - num;
    r1[i] = lower_bound(num + 1, num + cnt + 1, r1[i]) - num;
    max1[r1[i]] = max(max1[r1[i]], l1[i]);
  }
  for (int i = 1; i <= m; i++) {
    l2[i] = lower_bound(num + 1, num + cnt + 1, l2[i]) - num;
    r2[i] = lower_bound(num + 1, num + cnt + 1, r2[i]) - num;
    max2[r2[i]] = max(max2[r2[i]], l2[i]);
  }
  long long s = 1;
  for (int i = 2; i <= cnt; i++) {
    long long s1 = tr1.query(), s2 = tr2.query();
    tr1.update(1, cnt, 1, i - 1, (s + s2) % 1000000007);
    tr2.update(1, cnt, 1, i - 1, (s + s1) % 1000000007);
    s = (s + s1 + s2) % 1000000007 *
        (pow_mod(2, num[i] - num[i - 1]) - 2LL + 1000000007) % 1000000007;
    if (max1[i]) tr2.clear(1, cnt, 1, 1, max1[i]);
    if (max2[i]) tr1.clear(1, cnt, 1, 1, max2[i]);
  }
  s = (s + tr1.query() + tr2.query()) % 1000000007;
  printf("%lld\n", s);
  return 0;
}
