#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
struct SegTree {
  static const int maxn = 4e5 + 5;
  int st[maxn << 2];
  int lz[maxn << 2];
  SegTree() { memset(lz, -1, sizeof(lz)); }
  void push(int p, int L, int R) {
    if (~lz[p]) {
      st[p] = mult(lz[p], R - L + 1);
      if (L < R) {
        lz[p << 1] = lz[p];
        lz[p << 1 | 1] = lz[p];
      }
      lz[p] = -1;
    }
  }
  void pull(int p) {
    st[p] = st[p << 1] + st[p << 1 | 1];
    st[p] -= st[p] >= MOD ? MOD : 0;
  }
  void upd(int p, int l, int r, int L, int R, int val) {
    push(p, L, R);
    if (r < L || R < l) return;
    if (l <= L && R <= r) {
      lz[p] = val;
      push(p, L, R);
      return;
    }
    upd(p << 1, l, r, L, L + R >> 1, val);
    upd(p << 1 | 1, l, r, (L + R >> 1) + 1, R, val);
    pull(p);
  }
  int query(int p, int l, int r, int L, int R) {
    push(p, L, R);
    if (r < L || R < l) return 0;
    if (l <= L && R <= r) return st[p];
    int res = query(p << 1, l, r, L, L + R >> 1) +
              query(p << 1 | 1, l, r, (L + R >> 1) + 1, R);
    res -= res >= MOD ? MOD : 0;
    return res;
  }
} seg[2];
const int maxn = 4e5 + 5;
int k, n, m;
int l[maxn];
int r[maxn];
vector<int> g[maxn];
void chemthan() {
  cin >> k >> n >> m;
  vector<int> dc;
  dc.push_back(1), dc.push_back(k + 1);
  for (int i = (0); i < (n + m); ++i) {
    cin >> l[i] >> r[i], r[i]++;
    dc.push_back(l[i]), dc.push_back(r[i]);
  }
  sort((dc).begin(), (dc).end()),
      (dc).erase(unique((dc).begin(), (dc).end()), (dc).end());
  for (int i = (0); i < (n + m); ++i) {
    l[i] = lower_bound((dc).begin(), (dc).end(), l[i]) - dc.begin();
    r[i] = lower_bound((dc).begin(), (dc).end(), r[i]) - dc.begin();
    g[l[i]].push_back(i);
  }
  for (int i = (0); i < (1); ++i) {
    seg[i].upd(1, int((dc).size()) - 1, int((dc).size()) - 1, 0,
               int((dc).size()) - 1, 1);
  }
  for (int i = (0); i < (int((dc).size()) - 1); ++i) {
    vector<pair<pair<int, int>, int> > events;
    vector<pair<int, int> > events2;
    for (int j = (0); j < (2); ++j) {
      int mn = int((dc).size()) - 1;
      for (int x : g[i]) {
        if ((x < n ? 0 : 1) != j) {
          chkmin(mn, r[x] - 1);
        }
      }
      events.push_back(make_pair(
          make_pair(j ^ 1, mn),
          seg[j].query(1, i, int((dc).size()) - 1, 0, int((dc).size()) - 1)));
      events.push_back(make_pair(
          make_pair(j ^ 1, mn), seg[j ^ 1].query(1, mn, int((dc).size()) - 1, 0,
                                                 int((dc).size()) - 1)));
      events2.push_back(make_pair(j ^ 1, mn));
    }
    int num = fpow(2, dc[i + 1] - dc[i]);
    submod(num, 2);
    int tmp = 0;
    for (int j = (0); j < (2); ++j) {
      addmod(tmp,
             seg[j].query(1, i, int((dc).size()) - 1, 0, int((dc).size()) - 1));
    }
    events.push_back(
        make_pair(make_pair(0, int((dc).size()) - 1), mult(num, tmp)));
    for (auto it : events2) {
      int ix = it.first;
      int mn = it.second;
      seg[ix].upd(1, mn, int((dc).size()) - 1, 0, int((dc).size()) - 1, 0);
    }
    map<int, int> hs[2];
    for (auto it : events) {
      int ix = it.first.first;
      int u = it.first.second;
      int v = it.second;
      addmod(hs[ix][u], v);
    }
    for (int ix = (0); ix < (2); ++ix) {
      for (auto it : hs[ix]) {
        int u = it.first;
        int v = it.second;
        seg[ix].upd(1, u, u, 0, int((dc).size()) - 1, v);
      }
    }
  }
  int res = 0;
  for (int i = (0); i < (2); ++i) {
    addmod(res, seg[i].query(1, int((dc).size()) - 1, int((dc).size()) - 1, 0,
                             int((dc).size()) - 1));
  }
  cout << res << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
