#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
int add(int x, int y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
int mult(int x, int y) { return ((long long)x * y) % MOD; }
int bin_pow(int x, int p) {
  if (p == 0) return 1;
  if (p & 1) return mult(x, bin_pow(x, p - 1));
  return bin_pow(mult(x, x), p / 2);
}
const int N = 400400;
int n, m, k;
int xs[N + 5];
int a[N + 5][2], b[N + 5][2];
int bord[2][N + 5];
int dp[2][N + 5];
int sum0 = 0, sum1 = 0;
int lst;
int pt1 = 0, pt2 = 0;
int main() {
  k = 3;
  xs[0] = -1;
  xs[1] = 0;
  scanf("%d%d%d", &xs[2], &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i][0], &a[i][1]);
    a[i][0]--;
    xs[k++] = a[i][0];
    xs[k++] = a[i][1];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &b[i][0], &b[i][1]);
    b[i][0]--;
    xs[k++] = b[i][0];
    xs[k++] = b[i][1];
  }
  sort(xs, xs + k);
  k = unique(xs, xs + k) - xs;
  for (int i = 0; i < n; i++) {
    int l = lower_bound(xs, xs + k, a[i][0]) - xs;
    int r = lower_bound(xs, xs + k, a[i][1]) - xs;
    r--;
    bord[0][r] = max(bord[0][r], l);
  }
  for (int i = 0; i < m; i++) {
    int l = lower_bound(xs, xs + k, b[i][0]) - xs;
    int r = lower_bound(xs, xs + k, b[i][1]) - xs;
    r--;
    bord[1][r] = max(bord[1][r], l);
  }
  lst = 1;
  for (int i = 1; i < k - 1; i++) {
    int ways = bin_pow(2, xs[i + 1] - xs[i]);
    ways = sub(ways, 2);
    int nlst = mult(ways, add(add(sum0, sum1), lst));
    dp[0][i - 1] = add(sum1, lst);
    dp[1][i - 1] = add(sum0, lst);
    sum0 = add(sum0, dp[0][i - 1]);
    sum1 = add(sum1, dp[1][i - 1]);
    lst = nlst;
    while (pt1 < bord[0][i]) {
      sum0 = sub(sum0, dp[0][pt1]);
      pt1++;
    }
    while (pt2 < bord[1][i]) {
      sum1 = sub(sum1, dp[1][pt2]);
      pt2++;
    }
  }
  printf("%d\n", add(add(sum0, sum1), lst));
  return 0;
}
