#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long maxn = 400400;
long long n, m, k;
vector<long long> X;
map<long long, long long> I;
long long p[maxn], dp[maxn], up[maxn];
long long P[maxn], DP[maxn], UP[maxn];
map<long long, long long> a, b;
long long power(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % M;
    x = x * x % M;
    y /= 2;
  }
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> k >> n >> m;
  for (long long i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    r++;
    X.push_back(l);
    X.push_back(r);
    a[r] = max(a[r], l);
  }
  for (long long i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    r++;
    X.push_back(l);
    X.push_back(r);
    b[r] = max(b[r], l);
    ;
  }
  X.push_back(1);
  X.push_back(k + 1);
  sort(X.begin(), X.end());
  X.resize(unique(X.begin(), X.end()) - X.begin());
  p[0] = dp[0] = up[0] = 1;
  long long la = 0, lb = 0;
  for (long long i = 1; i < X.size(); i++) {
    long long len = X[i] - X[i - 1];
    long long z = power(2, len) - 2;
    long long B = p[i - 1] * z % M;
    long long U = 0, D = 0;
    if (b[X[i]]) {
      long long j = I[b[X[i]]];
      lb = max(lb, j);
      U = DP[i - 1] - DP[lb];
    } else
      U = p[i - 1];
    if (a[X[i]]) {
      long long j = I[a[X[i]]];
      la = max(la, j);
      D = UP[i - 1] - UP[la];
    } else
      D = p[i - 1];
    p[i] = ((B + U + D) % M + M) % M;
    dp[i] = ((B + D) % M + M) % M;
    up[i] = ((B + U) % M + M) % M;
    P[i] = (P[i - 1] + p[i]) % M;
    DP[i] = (DP[i - 1] + dp[i]) % M;
    UP[i] = (UP[i - 1] + up[i]) % M;
    I[X[i]] = i;
  }
  cout << p[X.size() - 1] << endl;
  return 0;
}
