#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;
stringstream sss;
const int maxn = 400010;
int k, n, m[2];
pair<int, int> A[2][maxn];
vector<int> inters[maxn][2];
vector<int> comp;
struct Segment {
  int seg[maxn * 2], zero = 0;
  void zero_to(int r) { zero = max(zero, (r)); }
  void add(int l, int r, int v) {
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) seg[l] = ((seg[l]) + (v)) % MOD, l++;
      if (r & 1) --r, seg[r] = ((seg[r]) + (v)) % MOD;
    }
  }
  int get(int pos) {
    if (pos < zero) return 0;
    int s = 0;
    for (pos += n; pos > 0; pos >>= 1) s = ((s) + (seg[pos])) % MOD;
    return s;
  }
} dp[2];
int poww(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) r = (1LL * (r) * (a)) % MOD;
    a = (1LL * (a) * (a)) % MOD;
    b >>= 1;
  }
  return r;
}
int get_id(int x) {
  return lower_bound((comp).begin(), (comp).end(), x) - comp.begin();
}
void MAIN() {
  cin >> k >> m[0] >> m[1];
  comp.emplace_back(k), comp.emplace_back(0);
  for (int t = (0); t < (2); ++t) {
    for (int i = (0); i < (m[t]); ++i) {
      int l, r;
      cin >> l >> r;
      --l;
      A[t][i] = {l, r};
      comp.emplace_back(l), comp.emplace_back(r);
    }
  }
  sort((comp).begin(), (comp).end());
  n = unique((comp).begin(), (comp).end()) - comp.begin();
  comp.resize(n);
  for (int t = (0); t < (2); ++t) {
    for (int i = (0); i < (m[t]); ++i) {
      A[t][i] = {get_id(A[t][i].first), get_id(A[t][i].second)};
      inters[A[t][i].second][t].emplace_back(i);
    }
  }
  for (int t = (0); t < (2); ++t) dp[t].add(0, 1, 1);
  for (int i = (1); i < (n); ++i) {
    int v = 1LL * dp[0].get(i - 1) * poww(2, comp[i] - comp[i - 1]) % MOD;
    for (int t = (0); t < (2); ++t) dp[t].add(i, i + 1, v);
    for (int t = (0); t < (2); ++t) {
      for (int ii : inters[i][t]) {
        int l, r;
        tie(l, r) = A[t][ii];
        dp[t ^ 1].zero_to(l);
        dp[t].add(i, i + 1, MOD - dp[t ^ 1].get(l));
        dp[t ^ 1].add(l, r + 1, MOD - dp[t ^ 1].get(l));
      }
    }
  }
  cout << dp[0].get(get_id(k)) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
60 5 7
1 3
50 60
1 60
30 45
20 40
4 5
6 37
5 18
50 55
22 27
25 31
44 45
5 2 4
1 3
3 5
2 2
4 5
    )";
  MAIN();
  return 0;
}
