#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
int seg[2][8 * maxN], lzy[2][8 * maxN];
int lt[maxN], rt[maxN], Q[2][2 * maxN], N;
vector<int> vec;
long long two_to_the_power_of(long long x) {
  if (x == 0) return 1;
  long long y = two_to_the_power_of(x / 2);
  y = y * y % MOD;
  if (x & 1) y = y * 2 % MOD;
  return y;
}
void apply(bool b, int id, int s, int e, int x) {
  seg[b][id] = 1ll * (e - s) * x % MOD;
  lzy[b][id] = x;
  return;
}
void shift(bool b, int id, int s, int e) {
  if (lzy[b][id] == -1) return;
  int md = (s + e) / 2;
  apply(b, 2 * id, s, md, lzy[b][id]);
  apply(b, 2 * id + 1, md, e, lzy[b][id]);
  lzy[b][id] = -1;
  return;
}
void update(bool b, int l, int r, int x, int id = 1, int s = 0, int e = N) {
  if (l <= s && e <= r) {
    apply(b, id, s, e, x);
    return;
  }
  if (l >= e || s >= r) return;
  shift(b, id, s, e);
  int md = (s + e) / 2;
  update(b, l, r, x, 2 * id, s, md);
  update(b, l, r, x, 2 * id + 1, md, e);
  seg[b][id] = (seg[b][2 * id] + seg[b][2 * id + 1]) % MOD;
  return;
}
int fetch(bool b, int l, int r, int id = 1, int s = 0, int e = N) {
  if (l <= s && e <= r) return seg[b][id];
  if (l >= e || s >= r) return 0;
  shift(b, id, s, e);
  int md = (s + e) / 2;
  return (fetch(b, l, r, 2 * id, s, md) + fetch(b, l, r, 2 * id + 1, md, e)) %
         MOD;
}
int main() {
  time_t START = clock();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(lzy, -1, sizeof lzy);
  int n, m, k;
  scanf("%d%d%d", &k, &n, &m);
  for (int i = 0; i < n + m; i++) {
    scanf("%d%d", lt + i, rt + i);
    vec.push_back(lt[i]);
    vec.push_back(rt[i]);
  }
  vec.push_back(0);
  vec.push_back(1);
  vec.push_back(k);
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  N = vec.size();
  for (int i = 0; i < n + m; i++) {
    lt[i] = lower_bound(vec.begin(), vec.end(), lt[i]) - vec.begin();
    rt[i] = lower_bound(vec.begin(), vec.end(), rt[i]) - vec.begin();
    Q[i < n][rt[i]] = max(Q[i < n][rt[i]], lt[i]);
  }
  update(0, 0, 1, 1);
  update(1, 0, 1, 1);
  for (int i = 1; i < N; i++) {
    update(0, 0, Q[1][i], 0);
    update(1, 0, Q[0][i], 0);
    if (i == N - 1) break;
    for (int b = 0; b < 2; b++) {
      int tmp = (1ll * fetch(b, 0, i) *
                 (two_to_the_power_of(vec[i + 1] - vec[i] - 1) - 1) % MOD) %
                MOD;
      tmp = (tmp + 1ll * fetch(1 - b, 0, i) *
                       two_to_the_power_of(vec[i + 1] - vec[i] - 1) % MOD) %
            MOD;
      update(b, i, i + 1, tmp);
    }
  }
  printf("%d\n", (seg[0][1] + seg[1][1]) % MOD);
  time_t FINISH = clock();
  cerr << "Execution time: "
       << (long double)(FINISH - START) / CLOCKS_PER_SEC * 1000.0
       << " milliseconds.\n";
  return 0;
}
