#include <bits/stdc++.h>
const int mo = 1e9 + 7;
const int maxn = 2e5 + 5;
using namespace std;
int rd() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x;
}
int k, n, m, b[maxn << 2], top;
pair<int, int> p[maxn][2];
int mi[maxn << 1][2], f[maxn << 1][3];
int ksm(int a, int b) {
  int sum = 1;
  for (; b; b >>= 1, a = 1LL * a * a % mo)
    if (b & 1) sum = 1LL * sum * a % mo;
  return sum;
}
int main() {
  k = rd();
  n = rd();
  m = rd();
  b[++top] = 0;
  b[++top] = k;
  for (int i = 1; i <= n; i++) {
    b[++top] = p[i][0].first = rd() - 1;
    b[++top] = p[i][0].second = rd();
  }
  for (int i = 1; i <= m; i++) {
    b[++top] = p[i][1].first = rd() - 1;
    b[++top] = p[i][1].second = rd();
  }
  sort(b + 1, b + top + 1);
  top = unique(b + 1, b + top + 1) - b - 1;
  for (int i = 1; i <= top; i++) mi[i][0] = mi[i][1] = top + 1;
  for (int i = 1; i <= n; i++) {
    p[i][0].first = lower_bound(b + 1, b + top + 1, p[i][0].first) - b;
    p[i][0].second = lower_bound(b + 1, b + top + 1, p[i][0].second) - b;
    mi[p[i][0].first][0] = min(mi[p[i][0].first][0], p[i][0].second);
  }
  for (int i = 1; i <= m; i++) {
    p[i][1].first = lower_bound(b + 1, b + top + 1, p[i][1].first) - b;
    p[i][1].second = lower_bound(b + 1, b + top + 1, p[i][1].second) - b;
    mi[p[i][1].first][1] = min(mi[p[i][1].first][1], p[i][1].second);
  }
  for (int i = top; i >= 1; i--) {
    mi[i - 1][0] = min(mi[i - 1][0], mi[i][0]);
    mi[i - 1][1] = min(mi[i - 1][1], mi[i][1]);
  }
  f[top][0] = f[top][1] = f[top][2] = 1;
  for (int i = top - 1; i >= 1; i--) {
    int zero = (f[i + 1][0] - f[mi[i][0]][0] + mo) % mo;
    int one = (f[i + 1][1] - f[mi[i][1]][1] + mo) % mo;
    int two = (1LL * f[i + 1][2] * (ksm(2, (b[i + 1] - b[i])) - 2 + mo)) % mo;
    f[i][0] = (1LL * f[i + 1][0] + one + two) % mo;
    f[i][1] = (1LL * f[i + 1][1] + zero + two) % mo;
    f[i][2] = (1LL * zero + one + two) % mo;
  }
  printf("%d\n", f[1][2]);
  return 0;
}
