#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int l[400105], r[400105];
int L[2][400105];
map<int, int> mp;
int cnt, dp[2][400105];
int rid[400105];
void fmain(int ID) {
  scanf("%d%d%d", &k, &n, &m);
  mp[1];
  mp[k];
  for (int(i) = 1; (i) <= (int)(n + m); (i)++) {
    scanf("%d%d", l + i, r + i);
    mp[l[i]];
    mp[r[i]];
  }
  for (auto &p : mp) {
    p.second = ++cnt;
    rid[cnt] = p.first;
  }
  for (int(i) = 1; (i) <= (int)(n + m); (i)++) {
    l[i] = mp[l[i]];
    r[i] = mp[r[i]];
    L[i <= n][r[i]] = max(l[i], L[i <= n][r[i]]);
  }
  dp[0][0] = 1;
  dp[1][0] = 1;
  int ps0 = 1, ps1 = 1;
  int st0 = 0, st1 = 0;
  while (st0 < L[0][1]) {
    addmod(ps0, 1000000007 - dp[0][st0]);
    st0++;
  }
  while (st1 < L[1][1]) {
    addmod(ps1, 1000000007 - dp[1][st1]);
    st1++;
  }
  for (int i = 2; i <= cnt; i++) {
    addmod(dp[1][i - 1], ps0);
    addmod(dp[0][i - 1], ps1);
    int len = rid[i] - rid[i - 1];
    if (len > 1) {
      int ws = fastPow(2, len - 1) - 1;
      addmod(dp[0][i - 1], (long long)ps0 * (ws) % 1000000007);
      addmod(dp[1][i - 1], (long long)ps0 * ws % 1000000007);
      addmod(dp[0][i - 1], (long long)ps1 * ws % 1000000007);
      addmod(dp[1][i - 1], (long long)ps1 * ws % 1000000007);
    }
    addmod(ps0, dp[0][i - 1]);
    addmod(ps1, dp[1][i - 1]);
    while (st0 < L[0][i]) {
      addmod(ps0, 1000000007 - dp[0][st0]);
      st0++;
    }
    while (st1 < L[1][i]) {
      addmod(ps1, 1000000007 - dp[1][st1]);
      st1++;
    }
  }
  printf("%d\n", (ps0 + ps1) % 1000000007);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
