#include <bits/stdc++.h>
using namespace std;
int n, cnt[2], tp[2];
int pre[2][2][100005];
int sum[2][2][100005];
pair<int, int> a[2][100005];
void upd(int& x, int y) { (x += y) >= 1000000007 ? x -= 1000000007 : 233; }
int power(int x, int y) {
  int s = 1;
  for (; y; y /= 2, x = 1ll * x * x % 1000000007)
    if (y & 1) s = 1ll * s * x % 1000000007;
  return s;
}
int main() {
  scanf("%d%d%d", &n, &cnt[0], &cnt[1]);
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      int r;
      scanf("%d%d", &a[i][j].first, &r);
      a[i][j].second = -r - 1;
    }
    int sz = 0;
    sort(a[i], a[i] + cnt[i]);
    for (int j = 0; j < cnt[i]; j++) {
      for (; sz && -a[i][j].second <= a[i][sz - 1].second; sz--)
        ;
      a[i][sz] = a[i][j];
      a[i][sz++].second *= -1;
    }
    cnt[i] = sz;
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      int p = -1;
      for (int k = 0; k < cnt[i]; k++) {
        for (; p + 1 < cnt[j] && a[j][p + 1].second <= a[i][k].first; p++)
          ;
        pre[i][j][k] = p + 1;
      }
    }
  sum[0][0][0] = 1;
  for (; tp[0] < cnt[0] || tp[1] < cnt[1];) {
    int k = (tp[0] == cnt[0] ||
             (tp[1] < cnt[1] && a[0][tp[0]].second > a[1][tp[1]].second));
    int& i = tp[k];
    int dp = 1ll *
             (1000000007 - power(500000004, a[k][i].second - a[k][i].first)) *
             (sum[0][k ^ 1][pre[k][k ^ 1][i]] + sum[0][k][pre[k][k][i]]) %
             1000000007;
    upd(dp, 1ll * (1000000007 - power(500000004, a[k][i].second)) *
                (sum[1][k][i] + 1000000007 - sum[1][k][pre[k][k][i]]) %
                1000000007);
    sum[0][k][i + 1] = sum[0][k][i];
    upd(sum[0][k][i + 1], dp);
    sum[1][k][i + 1] = sum[1][k][i];
    upd(sum[1][k][i + 1], 1ll * dp * power(2, a[k][i].second) % 1000000007);
    i++;
  }
  int ans = sum[0][0][cnt[0]];
  upd(ans, sum[0][1][cnt[1]]);
  printf("%d", 1ll * power(2, n) * ans % 1000000007);
}
