#include <bits/stdc++.h>
using namespace std;
struct data {
  int l, r, id;
} q[400009];
inline int qpow(int y) {
  long long x = 2, ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % 1000000007;
    y >>= 1;
    x = x * x % 1000000007;
  }
  return ans;
}
struct Queue {
  int h, t, L[400009], R[400009], sum, s[400009], a[400009];
  Queue() { h = t = L[1] = R[1] = s[1] = a[1] = sum = 1; }
  void updata(int l, int r, int tmp) {
    if (R[t] < r) {
      t++, L[t] = R[t] = R[t - 1] + 1, s[t] = a[t] = tmp,
           sum = (sum + tmp) % 1000000007;
      if (R[t] < r)
        t++, L[t] = R[t - 1] + 1, R[t] = r, a[t] = sum,
             s[t] = (long long)(qpow(R[t] - L[t] + 1) - 1 + 1000000007) * a[t] %
                    1000000007,
             sum = (sum + s[t]) % 1000000007;
    }
    while (h <= t && R[h] <= l) sum = (sum - s[h++] + 1000000007) % 1000000007;
    if (h <= t && L[h] <= l) {
      a[h] = (long long)a[h] * qpow(l - L[h] + 1) % 1000000007, L[h] = l + 1;
      sum = (sum - s[h] + 1000000007) % 1000000007;
      s[h] = (long long)(qpow(R[h] - L[h] + 1) - 1 + 1000000007) * a[h] %
             1000000007;
      sum = (sum + s[h]) % 1000000007;
    }
  }
} Q[2];
inline bool cmp(const data &A, const data &B) { return A.r < B.r; }
int main() {
  int k, n, m, a, b;
  scanf("%d%d%d", &k, &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = 0;
  for (int i = n + 1; i <= n + m; i++)
    scanf("%d%d", &q[i].l, &q[i].r), q[i].id = 1;
  sort(q + 1, q + n + m + 1, cmp);
  for (int i = 1; i <= n + m; i++) {
    a = Q[0].sum, b = Q[1].sum;
    if (!q[i].id)
      Q[0].updata(0, q[i].r, b), Q[1].updata(q[i].l, q[i].r, a);
    else
      Q[0].updata(q[i].l, q[i].r, b), Q[1].updata(0, q[i].r, a);
  }
  a = Q[0].sum, b = Q[1].sum;
  Q[0].updata(0, k, b), Q[1].updata(0, k, a);
  printf("%d", (Q[0].sum + Q[1].sum) % 1000000007);
  return 0;
}
