#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
int mul(int x, int y) {
  long long z = 1LL * x * y;
  return z - z / mod * mod;
}
int powt(int x, int y) {
  int r = 1;
  while (y) {
    if (y & 1) r = mul(r, x);
    x = mul(x, x);
    y >>= 1;
  }
  return r;
}
pair<int, int> fa[maxn], fb[maxn];
vector<int> w;
int pre[maxn * 4][2], dp[maxn * 4][3], d[3];
int get_id(int x) { return lower_bound(w.begin(), w.end(), x) - w.begin(); }
int main() {
  int n, m, cnt, k, i, j, l, r;
  scanf("%d%d%d", &k, &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &l, &r);
    w.push_back(--l);
    w.push_back(r);
    fa[i] = pair<int, int>(l, r);
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &l, &r);
    w.push_back(--l);
    w.push_back(r);
    fb[i] = pair<int, int>(l, r);
  }
  w.push_back(0);
  w.push_back(k);
  sort(w.begin(), w.end());
  w.erase(unique(w.begin(), w.end()), w.end());
  cnt = w.size();
  for (i = 0; i < cnt; i++) pre[i][0] = pre[i][1] = cnt;
  for (i = 0; i < n; i++) {
    fa[i].first = get_id(fa[i].first);
    fa[i].second = get_id(fa[i].second);
    pre[fa[i].first][0] = min(pre[fa[i].first][0], fa[i].second);
  }
  for (i = 0; i < m; i++) {
    fb[i].first = get_id(fb[i].first);
    fb[i].second = get_id(fb[i].second);
    pre[fb[i].first][1] = min(pre[fb[i].first][1], fb[i].second);
  }
  for (i = cnt - 2; i >= 0; i--) {
    for (j = 0; j < 2; j++) pre[i][j] = min(pre[i][j], pre[i + 1][j]);
  }
  dp[cnt - 1][0] = dp[cnt - 1][1] = dp[cnt - 1][2] = 1;
  for (i = cnt - 2; i >= 0; i--) {
    for (j = 0; j < 2; j++) d[j] = add(dp[i + 1][j], mod - dp[pre[i][j]][j]);
    d[2] = mul(dp[i + 1][2], add(powt(2, w[i + 1] - w[i]), mod - 2));
    dp[i][0] = add(dp[i + 1][0], add(d[1], d[2]));
    dp[i][1] = add(dp[i + 1][1], add(d[0], d[2]));
    dp[i][2] = add(d[0], add(d[1], d[2]));
  }
  printf("%d\n", dp[0][2]);
  return 0;
}
