#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1000000007;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
int L, n, m0, m1;
vector<int> v;
pair<int, int> s0[100111], s1[100111];
long long dp[2][400111], sum[2][400111];
int getid(int x) { return upper_bound(v.begin(), v.end(), x) - v.begin(); }
long long calc() {
  int it0 = 1, it1 = 1, mx0 = 0, mx1 = 0;
  sum[0][0] = sum[1][0] = 1;
  for (int i = 1; i <= n; i++) {
    while (it0 <= m0 && s0[it0].first <= i) mx0 = max(mx0, s0[it0++].second);
    while (it1 <= m1 && s1[it1].first <= i) mx1 = max(mx1, s1[it1++].second);
    if (mx0 < i)
      dp[0][i] = (sum[1][i - 1] - (mx0 == 0 ? 0 : sum[1][mx0 - 1]) + mod) % mod;
    if (mx1 < i)
      dp[1][i] = (sum[0][i - 1] - (mx1 == 0 ? 0 : sum[0][mx1 - 1]) + mod) % mod;
    int l = v[i] - v[i - 1];
    long long c = qpow(2, l - 1) - 1 + mod;
    sum[0][i] = ((c + 1) * dp[0][i] + c * dp[1][i] + sum[0][i - 1]) % mod;
    sum[1][i] = (c * dp[0][i] + (c + 1) * dp[1][i] + sum[1][i - 1]) % mod;
    if (i == n) return ((c + 1) * (dp[0][i] + dp[1][i]) % mod + mod) % mod;
  }
  return 1;
}
int main() {
  v.push_back(1);
  L = getnum(), m0 = getnum(), m1 = getnum();
  v.push_back(L + 1);
  for (int i = 1; i <= m0; i++) {
    int l, r;
    l = getnum(), r = getnum();
    v.push_back(l);
    v.push_back(r);
    s0[i] = make_pair(r, l);
  }
  for (int i = 1; i <= m1; i++) {
    int l, r;
    l = getnum(), r = getnum();
    v.push_back(l);
    v.push_back(r);
    s1[i] = make_pair(r, l);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  sort(s0 + 1, s0 + m0 + 1);
  sort(s1 + 1, s1 + m1 + 1);
  for (int i = 1; i <= m0; i++)
    s0[i] = make_pair(getid(s0[i].first), getid(s0[i].second));
  for (int i = 1; i <= m1; i++)
    s1[i] = make_pair(getid(s1[i].first), getid(s1[i].second));
  n = v.size() - 1;
  putnum(calc()), putchar('\n');
  return 0;
}
