#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 20;
const int mod = 1e9 + 7;
int l[maxn], r[maxn];
vector<int> rq[2][maxn], tmp;
void mkay(int &a) {
  if (a >= mod)
    a -= mod;
  else if (a < 0)
    a += mod;
}
int sum[2][maxn * 4], lazy[2][maxn * 4];
void put(int s, int e, int v, int id, int val) {
  sum[id][v] = 1LL * (e - s) * val % mod;
  lazy[id][v] = val;
}
void shift(int s, int e, int v, int id) {
  if (e - s >= 2 && lazy[id][v] != -1) {
    int m = (s + e) / 2;
    put(s, m, 2 * v, id, lazy[id][v]);
    put(m, e, 2 * v + 1, id, lazy[id][v]);
  }
  lazy[id][v] = -1;
}
void Set(int l, int r, int val, int s, int e, int v, int id) {
  if (l <= s && e <= r) {
    put(s, e, v, id, val);
    return;
  }
  if (r <= s || e <= l) return;
  shift(s, e, v, id);
  int m = (s + e) / 2;
  Set(l, r, val, s, m, 2 * v, id);
  Set(l, r, val, m, e, 2 * v + 1, id);
  mkay(sum[id][v] = sum[id][2 * v] + sum[id][2 * v + 1]);
}
int getdp(int l, int r, int s, int e, int v, int id) {
  if (l <= s && e <= r) return sum[id][v];
  if (r <= s || e <= l) return 0;
  shift(s, e, v, id);
  int m = (s + e) / 2, ans = 0;
  mkay(ans = getdp(l, r, s, m, 2 * v, id) + getdp(l, r, m, e, 2 * v + 1, id));
  return ans;
}
int pw(int b) {
  if (!b) return 1;
  int x = pw(b / 2);
  x = 1LL * x * x % mod;
  if (b & 1) x = 2LL * x % mod;
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(lazy, -1, sizeof lazy);
  int k, n, m;
  cin >> k >> n >> m;
  tmp.push_back(0);
  tmp.push_back(1);
  tmp.push_back(k);
  for (int i = 0; i < n + m; i++) {
    cin >> l[i] >> r[i];
    tmp.push_back(l[i]);
    tmp.push_back(r[i]);
  }
  sort(tmp.begin(), tmp.end());
  tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
  for (int i = 0; i < n + m; i++) {
    l[i] = lower_bound(tmp.begin(), tmp.end(), l[i]) - tmp.begin();
    r[i] = lower_bound(tmp.begin(), tmp.end(), r[i]) - tmp.begin();
    rq[i < n][r[i]].push_back(l[i]);
  }
  n = (int)tmp.size();
  Set(0, 1, 1, 0, n, 1, 0);
  Set(0, 1, 1, 0, n, 1, 1);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      int shit = 0;
      for (auto ind : rq[j][i]) shit = max(shit, ind);
      Set(0, shit, 0, 0, n, 1, !j);
    }
    if (i + 1 < n) {
      for (int x = 0; x < 2; x++) {
        int upd = 0;
        mkay(upd += 1LL * getdp(0, i, 0, n, 1, x) *
                    (pw(tmp[i + 1] - tmp[i] - 1) - 1 + mod) % mod);
        mkay(upd += 1LL * getdp(0, i, 0, n, 1, !x) *
                    pw(tmp[i + 1] - tmp[i] - 1) % mod);
        Set(i, i + 1, upd, 0, n, 1, x);
      }
    }
  }
  int res = 0;
  for (int j = 0; j < 2; j++) mkay(res += sum[j][1]);
  cout << res << endl;
}
