#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
vector<pair<int, int>> q1, q2, w1, w2;
vector<int> Q;
int k, n, m;
int x, y;
map<pair<int, int>, long long> qwe[500000];
long long powe(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
long long take2(long long num) { return (powe(2, num) - 2 + mod) % mod; }
int main() {
  cin >> k >> n >> m;
  for (int i = (0); i < (n); i++) {
    cin >> x >> y;
    x--;
    y--;
    q1.push_back(make_pair(x, y));
  }
  for (int i = (0); i < (m); i++) {
    cin >> x >> y;
    x--;
    y--;
    q2.push_back(make_pair(x, y));
  }
  sort(q1.begin(), q1.end());
  sort(q2.begin(), q2.end());
  for (int i = (0); i < (q1.size()); i++) {
    while (w1.size() && w1.back().second >= q1[i].second) w1.pop_back();
    w1.push_back(q1[i]);
  }
  for (int i = (0); i < (q2.size()); i++) {
    while (w2.size() && w2.back().second >= q2[i].second) w2.pop_back();
    w2.push_back(q2[i]);
  }
  map<int, int> u;
  u[0] = 0;
  u[k] = 0;
  for (int i = (0); i < (w1.size()); i++)
    u[w1[i].first] = 0, u[w1[i].second + 1] = 0;
  for (int i = (0); i < (w2.size()); i++)
    u[w2[i].first] = 0, u[w2[i].second + 1] = 0;
  int g = 0;
  for (map<int, int>::iterator it = u.begin(); it != u.end(); it++)
    Q.push_back(it->first), it->second = g, g++;
  for (int i = (0); i < (w1.size()); i++)
    w1[i].first = u[w1[i].first], w1[i].second = u[w1[i].second + 1];
  for (int i = (0); i < (w2.size()); i++)
    w2[i].first = u[w2[i].first], w2[i].second = u[w2[i].second + 1];
  qwe[0][make_pair(0, 0)] = 1;
  for (int i = (0); i < (Q.size() - 1); i++) {
    long pf =
        lower_bound(w1.begin(), w1.end(), make_pair(i, (int)mod)) - w1.begin();
    long ps =
        lower_bound(w2.begin(), w2.end(), make_pair(i, (int)mod)) - w2.begin();
    for (map<pair<int, int>, long long>::iterator it = qwe[i].begin();
         it != qwe[i].end(); it++) {
      pair<int, int> pos = it->first;
      long long res = it->second;
      long long num = Q[i + 1] - Q[i];
      if (pos.second == w2.size() || w2[pos.second].second > i + 1) {
        qwe[i + 1][make_pair(pf, pos.second)] += res;
        qwe[i + 1][make_pair(pf, pos.second)] %= mod;
      }
      if (pos.first == w1.size() || w1[pos.first].second > i + 1) {
        qwe[i + 1][make_pair(pos.first, ps)] += res;
        qwe[i + 1][make_pair(pos.first, ps)] %= mod;
      }
      if (num > 1) {
        res = (res * take2(num)) % mod;
        qwe[i + 1][make_pair(pf, ps)] += res;
        qwe[i + 1][make_pair(pf, ps)] %= mod;
      }
    }
  }
  cout << qwe[Q.size() - 1][make_pair(w1.size(), w2.size())];
  return 0;
}
