#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10, mod = 1e9 + 7;
struct nude {
  int sum = 0;
  bool emp = false;
} seg[3][N << 2];
int n, m, k, l[N], r[N], val;
vector<int> vec;
vector<pair<int, int> > q[N];
void compress() {
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int i = 0; i < n + m; i++) {
    l[i] = lower_bound(vec.begin(), vec.end(), l[i]) - vec.begin();
    r[i] = lower_bound(vec.begin(), vec.end(), r[i]) - vec.begin();
    q[r[i]].push_back({l[i], (i >= n)});
  }
  k = vec.size();
}
int power(int a, int b) {
  if (b == 0) return 1;
  int rtr = power(a, b / 2);
  if (b % 2) return 1ll * rtr * rtr % mod * a % mod;
  return 1ll * rtr * rtr % mod;
}
void relax(int typ, int id) {
  int lc = id * 2, rc = lc + 1;
  if (!seg[typ][id].emp) return;
  seg[typ][lc].emp = 1, seg[typ][lc].sum = 0;
  seg[typ][rc].emp = 1, seg[typ][rc].sum = 0;
  seg[typ][id].emp = 0;
  return;
}
void add(int typ, int p, int id = 1, int s = 0, int e = k) {
  if (e - s == 1) {
    seg[typ][id].sum = (seg[typ][id].sum + val) % mod;
    return;
  }
  int mid = (s + e) / 2, lc = id * 2, rc = lc + 1;
  relax(typ, id);
  if (p < mid)
    add(typ, p, lc, s, mid);
  else
    add(typ, p, rc, mid, e);
  seg[typ][id].sum = (seg[typ][lc].sum + seg[typ][rc].sum) % mod;
  return;
}
int get(int typ, int l, int r, int id = 1, int s = 0, int e = k) {
  if (l <= s && e <= r) return seg[typ][id].sum;
  if (e <= l || r <= s) return 0;
  int mid = (s + e) / 2, lc = id * 2, rc = lc + 1;
  relax(typ, id);
  return (get(typ, l, r, lc, s, mid) + get(typ, l, r, rc, mid, e)) % mod;
}
void emp(int typ, int l, int r, int id = 1, int s = 0, int e = k) {
  if (l <= s && e <= r) {
    seg[typ][id].emp = 1;
    seg[typ][id].sum = 0;
    return;
  }
  if (e <= l || r <= s) return;
  int mid = (s + e) / 2, lc = id * 2, rc = lc + 1;
  relax(typ, id);
  emp(typ, l, r, lc, s, mid);
  emp(typ, l, r, rc, mid, e);
  seg[typ][id].sum = (seg[typ][lc].sum + seg[typ][rc].sum) % mod;
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> k >> n >> m;
  vec.push_back(0), vec.push_back(k);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    vec.push_back(l[i]);
    vec.push_back(r[i]);
  }
  for (int i = n; i < n + m; i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    vec.push_back(l[i]);
    vec.push_back(r[i]);
  }
  compress();
  val = 1;
  add(0, 0);
  add(1, 0);
  for (int i = 1; i < k; i++) {
    int fr = seg[0][1].sum;
    val = 1ll * (power(2, vec[i] - vec[i - 1]) - 1 + mod) % mod * fr % mod;
    add(0, i);
    add(1, i);
    for (auto p : q[i]) {
      int ll = p.first, typ = p.second;
      val = get(typ, 0, ll + 1);
      val = mod - val;
      add(1 - typ, i);
      emp(typ, 0, ll + 1);
    }
  }
  cout << seg[0][1].sum;
  return 0;
}
