#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10001;
const long long mod = 1e9 + 7;
int n, m, k;
int baze[2][maxn];
long long dp[2][maxn], Sum[2][maxn], Ans[maxn], Po[2];
vector<int> tmp;
int l1[maxn], r1[maxn], l2[maxn], r2[maxn];
inline long long _s(long long i, long long j) {
  i = (i + j) % mod;
  if (i < 0) i += mod;
  return i;
}
inline long long _z(long long i, long long j) { return (i * j) % mod; }
long long Pow(long long i, int j) {
  if (!j) return 1;
  long long ret = Pow(i, j / 2);
  ret = _z(ret, ret);
  if (j & 1) ret = _z(ret, i);
  return ret;
}
void Compress() {
  sort(tmp.begin(), tmp.end());
  tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
}
void Do_Compress() {
  for (int y = 0; y < 1LL * tmp.size() + 3; y++) baze[0][y] = baze[1][y] = -1;
  for (int y = 1; y <= n; y++)
    l1[y] = lower_bound(tmp.begin(), tmp.end(), l1[y]) - tmp.begin(),
    r1[y] = lower_bound(tmp.begin(), tmp.end(), r1[y] + 1) - tmp.begin() - 1,
    baze[0][r1[y]] = max(baze[0][r1[y]], l1[y]);
  for (int y = 1; y <= m; y++)
    l2[y] = lower_bound(tmp.begin(), tmp.end(), l2[y]) - tmp.begin(),
    r2[y] = lower_bound(tmp.begin(), tmp.end(), r2[y] + 1) - tmp.begin() - 1,
    baze[1][r2[y]] = max(baze[1][r2[y]], l2[y]);
}
void upd(bool e, int i) {
  Sum[e][i] = _s(Sum[e][i] - dp[e][i - 1], Sum[e][i - 1] + Sum[1 - e][i - 1]);
  dp[e][i - 1] = Sum[1 - e][i - 1];
  if (baze[1 - e][i] < 0) return;
  for (int y = Po[1 - e]; y < baze[1 - e][i]; y++)
    Sum[e][i] = _s(Sum[e][i], -dp[e][y]), dp[e][y] = 0;
  Po[1 - e] = max(Po[1 - e], 1LL * baze[1 - e][i]);
}
void Upd_Dp() {
  Ans[0] = dp[0][0] = dp[1][0] = Sum[0][0] = Sum[1][0] = 1;
  for (int y = 1; y < 1LL * tmp.size() - 1; y++) {
    long long hel = _s(-2, Pow(2, tmp[y + 1] - tmp[y]));
    dp[0][y] = dp[1][y] = Sum[1][y] = Sum[0][y] = _z(hel, Ans[y - 1]);
    upd(1, y);
    upd(0, y);
    Ans[y] = _s(Sum[0][y] + Sum[1][y], -dp[0][y]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> k >> n >> m;
  tmp.push_back(0), tmp.push_back(1), tmp.push_back(k + 1);
  for (int y = 1; y <= n; y++)
    cin >> l1[y] >> r1[y], tmp.push_back(l1[y]), tmp.push_back(r1[y] + 1);
  for (int y = 1; y <= m; y++)
    cin >> l2[y] >> r2[y], tmp.push_back(l2[y]), tmp.push_back(r2[y] + 1);
  Compress();
  Do_Compress();
  Upd_Dp();
  cout << Ans[1LL * tmp.size() - 2] << endl;
  return 0;
}
