#include <bits/stdc++.h>
using namespace std;
const int N = 1e5, mod = 1e9 + 7;
pair<int, int> p[2][N];
int tt, mp[N * 4 + 2], mn[2][N * 4 + 2], f[N * 4 + 2][3];
int pw(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
void chkmn(int &x, int y) { x = min(x, y); }
int fnd(int &x) { return x = lower_bound(mp, mp + tt + 1, x) - mp; }
int main() {
  int k, n, m;
  tt = 0;
  scanf("%d%d%d", &k, &n, &m);
  mp[++tt] = k;
  for (int i = 0, l, r; i < n; i++) {
    scanf("%d%d", &l, &r);
    mp[++tt] = p[0][i].first = l - 1;
    mp[++tt] = p[0][i].second = r;
  }
  for (int i = 0, l, r; i < m; i++) {
    scanf("%d%d", &l, &r);
    mp[++tt] = p[1][i].first = l - 1;
    mp[++tt] = p[1][i].second = r;
  }
  sort(mp, mp + tt + 1);
  tt = unique(mp, mp + tt + 1) - mp - 1;
  for (int i = 0; i <= tt; i++) mn[0][i] = mn[1][i] = tt + 1;
  for (int i = 0; i < n; i++)
    chkmn(mn[0][fnd(p[0][i].first)], fnd(p[0][i].second));
  for (int i = tt; i; i--) mn[0][i - 1] = min(mn[0][i - 1], mn[0][i]);
  for (int i = 0; i < m; i++)
    chkmn(mn[1][fnd(p[1][i].first)], fnd(p[1][i].second));
  for (int i = tt; i; i--) mn[1][i - 1] = min(mn[1][i - 1], mn[1][i]);
  f[tt][0] = f[tt][1] = f[tt][2] = 1;
  for (int i = tt - 1, g[3]; i >= 0; i--) {
    g[0] = (f[i + 1][0] - f[mn[0][i]][0] + mod) % mod;
    g[1] = (f[i + 1][1] - f[mn[1][i]][1] + mod) % mod;
    g[2] =
        1ll * f[i + 1][2] * ((pw(2, mp[i + 1] - mp[i]) - 2 + mod) % mod) % mod;
    f[i][0] = ((long long)f[i + 1][0] + g[1] + g[2]) % mod;
    f[i][1] = ((long long)f[i + 1][1] + g[0] + g[2]) % mod;
    f[i][2] = ((long long)g[0] + g[1] + g[2]) % mod;
  }
  printf("%d\n", f[0][2]);
  return 0;
}
