#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <unsigned int mod_>
struct ModInt {
  using uint = unsigned int;
  using ll = long long;
  using ull = unsigned long long;
  constexpr static uint mod = mod_;
  uint v;
  ModInt() : v(0) {}
  ModInt(ll _v) : v(normS(_v % mod + mod)) {}
  explicit operator bool() const { return v != 0; }
  static uint normS(const uint& x) { return (x < mod) ? x : x - mod; }
  static ModInt make(const uint& x) {
    ModInt m;
    m.v = x;
    return m;
  }
  ModInt operator+(const ModInt& b) const { return make(normS(v + b.v)); }
  ModInt operator-(const ModInt& b) const { return make(normS(v + mod - b.v)); }
  ModInt operator-() const { return make(normS(mod - v)); }
  ModInt operator*(const ModInt& b) const { return make((ull)v * b.v % mod); }
  ModInt operator/(const ModInt& b) const { return *this * b.inv(); }
  ModInt& operator+=(const ModInt& b) { return *this = *this + b; }
  ModInt& operator-=(const ModInt& b) { return *this = *this - b; }
  ModInt& operator*=(const ModInt& b) { return *this = *this * b; }
  ModInt& operator/=(const ModInt& b) { return *this = *this / b; }
  ModInt& operator++(int) { return *this = *this + 1; }
  ModInt& operator--(int) { return *this = *this - 1; }
  ll extgcd(ll a, ll b, ll& x, ll& y) const {
    ll p[] = {a, 1, 0}, q[] = {b, 0, 1};
    while (*q) {
      ll t = *p / *q;
      for (int i = 0; i < (int)(3); i++) swap(p[i] -= t * q[i], q[i]);
    }
    if (p[0] < 0)
      for (int i = 0; i < (int)(3); i++) p[i] = -p[i];
    x = p[1], y = p[2];
    return p[0];
  }
  ModInt inv() const {
    ll x, y;
    extgcd(v, mod, x, y);
    return make(normS(x + mod));
  }
  ModInt pow(ll p) const {
    if (p < 0) return inv().pow(-p);
    ModInt a = 1;
    ModInt x = *this;
    while (p) {
      if (p & 1) a *= x;
      x *= x;
      p >>= 1;
    }
    return a;
  }
  bool operator==(const ModInt& b) const { return v == b.v; }
  bool operator!=(const ModInt& b) const { return v != b.v; }
  friend istream& operator>>(istream& o, ModInt& x) {
    ll tmp;
    o >> tmp;
    x = ModInt(tmp);
    return o;
  }
  friend ostream& operator<<(ostream& o, const ModInt& x) { return o << x.v; }
};
using mint = ModInt<1000000007>;
struct segtree {
  using D = mint;
  int N;
  vector<D> val;
  segtree() {}
  segtree(int n) {
    N = 1;
    while (N < n) N *= 2;
    val.assign(N * 2, 0);
  }
  segtree(const vector<D>& ds) {
    int n = ds.size();
    N = 1;
    while (N < n) N *= 2;
    val.assign(N * 2, 0);
    for (int i = 0; i < (int)(n); i++) val[i + N] = ds[i];
    for (int i = N - 1; i > 0; i--) val[i] = val[i * 2] + val[i * 2 + 1];
  }
  void add(int k, D d) {
    k++;
    k += N;
    val[k] += d;
    k /= 2;
    while (k) {
      val[k] = val[k * 2] + val[k * 2 + 1];
      k /= 2;
    }
  }
  int E = -1;
  void erase(int x) { E = max(E, x); }
  D sum(int a, int b) {
    a = max(a, E);
    a++, b++;
    D res = 0;
    a += N, b += N;
    while (a < b) {
      if (a & 1) res += val[a++];
      if (b & 1) res += val[--b];
      a /= 2, b /= 2;
    }
    return res;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int L;
  cin >> L;
  V<int> xs;
  V<int> r2lO, r2lX;
  using P = pair<int, int>;
  {
    int NO, NX;
    cin >> NO >> NX;
    V<P> Os(NO), Xs(NX);
    for (int i = 0; i < (int)(NO); i++) {
      cin >> Os[i].first >> Os[i].second;
      Os[i].first--;
      xs.push_back(Os[i].first);
      xs.push_back(Os[i].second);
    }
    for (int i = 0; i < (int)(NX); i++) {
      cin >> Xs[i].first >> Xs[i].second;
      Xs[i].first--;
      xs.push_back(Xs[i].first);
      xs.push_back(Xs[i].second);
    }
    xs.push_back(0);
    xs.push_back(L);
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    int K = xs.size();
    r2lO = V<int>(K, -1);
    r2lX = V<int>(K, -1);
    for (int i = 0; i < (int)(NO); i++) {
      int x = lower_bound(xs.begin(), xs.end(), Os[i].first) - xs.begin();
      int y = lower_bound(xs.begin(), xs.end(), Os[i].second) - xs.begin();
      r2lO[y] = max(r2lO[y], x);
    }
    for (int i = 0; i < (int)(NX); i++) {
      int x = lower_bound(xs.begin(), xs.end(), Xs[i].first) - xs.begin();
      int y = lower_bound(xs.begin(), xs.end(), Xs[i].second) - xs.begin();
      r2lX[y] = max(r2lX[y], x);
    }
  }
  int K = xs.size();
  segtree O(K + 2), X(K + 2);
  mint M = 1;
  for (int i = 0; i < (int)(K - 1); i++) {
    mint Osum = O.sum(-1, i);
    mint Xsum = X.sum(-1, i);
    O.add(i - 1, Xsum + M);
    X.add(i - 1, Osum + M);
    M = (M + Osum + Xsum) * (mint(2).pow(xs[i + 1] - xs[i]) - 2);
    O.erase(r2lX[i + 1]);
    X.erase(r2lO[i + 1]);
  }
  cout << M + O.sum(-1, K) + X.sum(-1, K) << endl;
}
