#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 2147483647;
int a[100005][2], b[100005][2], ma[400005][2];
long long dp[400005][3], sum[400005][2];
long long pw(long long aa, long long nn) {
  long long ans = 1;
  while (nn) {
    if (nn & 1) ans = ans * aa % mod;
    aa = aa * aa % mod;
    nn >>= 1;
  }
  return ans;
}
vector<int> v;
int main() {
  int k, n, m;
  scanf("%d%d%d", &k, &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i][0], &a[i][1]);
    a[i][1]++;
    v.emplace_back(a[i][0]);
    v.emplace_back(a[i][1]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &b[i][0], &b[i][1]);
    b[i][1]++;
    v.emplace_back(b[i][0]);
    v.emplace_back(b[i][1]);
  }
  v.emplace_back(1), v.emplace_back(k + 1);
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  int num = v.size() - 1;
  for (int i = 0; i < n; i++) {
    a[i][0] = lower_bound(v.begin(), v.end(), a[i][0]) - v.begin() + 1;
    a[i][1] = lower_bound(v.begin(), v.end(), a[i][1]) - v.begin();
    ma[a[i][1]][0] = max(ma[a[i][1]][0], a[i][0]);
  }
  for (int i = 0; i < m; i++) {
    b[i][0] = lower_bound(v.begin(), v.end(), b[i][0]) - v.begin() + 1;
    b[i][1] = lower_bound(v.begin(), v.end(), b[i][1]) - v.begin();
    ma[b[i][1]][1] = max(ma[b[i][1]][1], b[i][0]);
  }
  dp[0][0] = 1;
  sum[0][0] = sum[0][1] = 1;
  int now1 = 0, now2 = 0;
  for (int i = 1; i <= num; i++) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) *
               (pw(2, v[i] - v[i - 1]) - 2) % mod;
    now1 = max(now1, ma[i][0]);
    if (now1 < i)
      dp[i][1] =
          (sum[i - 1][1] - sum[now1][1] + dp[now1][0] + dp[now1][2]) % mod;
    now2 = max(now2, ma[i][1]);
    if (now2 < i)
      dp[i][2] =
          (sum[i - 1][0] - sum[now2][0] + dp[now2][0] + dp[now2][1]) % mod;
    sum[i][0] = (sum[i - 1][0] + dp[i][0] + dp[i][1]) % mod;
    sum[i][1] = (sum[i - 1][1] + dp[i][0] + dp[i][2]) % mod;
  }
  dp[num][0] = (dp[num][0] + dp[num][1] + dp[num][2]) % mod;
  if (dp[num][0] < 0) dp[num][0] += mod;
  printf("%lld\n", dp[num][0]);
  return 0;
}
