#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 5e5 + 10, p = 1e9 + 7;
int n, m, k, b[M], bt = 0, mn[2][M];
long long f[M][3];
pair<int, int> a[2][N];
long long fpow(long long a, long long b) {
  long long c = 1;
  for (; b; b >>= 1, (a *= a) %= p)
    if (b & 1) (c *= a) %= p;
  return c;
}
int main() {
  scanf("%d%d%d", &k, &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[0][i].first, &a[0][i].second);
    b[++bt] = --a[0][i].first, b[++bt] = a[0][i].second;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[1][i].first, &a[1][i].second);
    b[++bt] = --a[1][i].first, b[++bt] = a[1][i].second;
  }
  b[0] = 0, b[++bt] = k;
  sort(b, b + bt + 1);
  bt = unique(b, b + bt + 1) - b - 1;
  for (int i = 0; i <= bt; i++) mn[0][i] = mn[1][i] = bt + 1;
  for (int i = 1; i <= n; i++) {
    a[0][i].first = lower_bound(b, b + bt + 1, a[0][i].first) - b;
    a[0][i].second = lower_bound(b, b + bt + 1, a[0][i].second) - b;
    mn[0][a[0][i].first] = min(mn[0][a[0][i].first], a[0][i].second);
  }
  for (int i = 1; i <= m; i++) {
    a[1][i].first = lower_bound(b, b + bt + 1, a[1][i].first) - b;
    a[1][i].second = lower_bound(b, b + bt + 1, a[1][i].second) - b;
    mn[1][a[1][i].first] = min(mn[1][a[1][i].first], a[1][i].second);
  }
  for (int i = bt; i; i--) {
    mn[0][i - 1] = min(mn[0][i - 1], mn[0][i]);
    mn[1][i - 1] = min(mn[1][i - 1], mn[1][i]);
  }
  f[bt][0] = f[bt][1] = f[bt][2] = 1;
  for (int i = bt - 1; i >= 0; i--) {
    (f[i][0] = f[i + 1][0] + f[i + 1][1] - f[mn[1][i]][1] +
               (fpow(2, b[i + 1] - b[i]) - 2) % p * f[i + 1][2] % p) %= p;
    (f[i][1] = f[i + 1][0] + f[i + 1][1] - f[mn[0][i]][0] +
               (fpow(2, b[i + 1] - b[i]) - 2) % p * f[i + 1][2] % p) %= p;
    (f[i][2] = f[i + 1][0] + f[i + 1][1] - f[mn[0][i]][0] - f[mn[1][i]][1] +
               (fpow(2, b[i + 1] - b[i]) - 2) % p * f[i + 1][2] % p) %= p;
  }
  printf("%lld\n", (f[0][2] + p) % p);
  return 0;
}
