#include <bits/stdc++.h>
using namespace std;
const int N = 300005, M = 45, P = 998244353;
int n, m, ans, L[N], R[N], f[N], a[N], b[N], s[N], p[N], g[M][N];
vector<int> v;
inline int bp(int x, int y) {
  int r = 1;
  for (; y; y = y >> 1, x = 1ll * x * x % P)
    if (y & 1) r = 1ll * r * x % P;
  return r;
}
inline int C(int x, int y) {
  return 1ll * f[x] * bp(1ll * f[x - y] * f[y] % P, P - 2) % P;
}
inline void add(int& x, int y) {
  if ((x += y) >= P) x -= P;
}
inline void sub(int& x, int y) {
  if ((x -= y) < 0) x += P;
}
int main() {
  scanf("%d%d", &n, &m), f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = 1ll * f[i - 1] * i % P;
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d%d", &L[i], &R[i]);
    s[R[i]]++, s[L[i] - 1]--;
  }
  for (int i = n; i >= 1; i--) s[i - 1] += s[i];
  for (int i = 1; i <= n; i++)
    if (s[i] >= i)
      for (int j = 0; j <= min(2 * m, i); j++)
        if (s[i] >= j) g[j][i] = C(s[i] - j, i - j);
  for (int i = 0; i <= 2 * m; i++)
    for (int j = 1; j <= n; j++) add(g[i][j], g[i][j - 1]);
  for (int i = 0; i < m; i++) scanf("%d%d", &a[i], &b[i]);
  ans = g[0][n];
  for (int S = 1; S < (1 << m); S++) {
    int l = 1, r = n, ll, rr, cnt = 0;
    v.clear();
    for (int j = 0; j < m; j++)
      if ((S >> j) & 1) {
        if (!p[a[j]]) v.push_back(a[j]), p[a[j]] = 1, cnt++;
        if (!p[b[j]]) v.push_back(b[j]), p[b[j]] = 1, cnt++;
      }
    for (int j = 0; j < m; j++)
      if ((S >> j) & 1) p[a[j]] = 0, p[b[j]] = 0;
    for (int i = 0; i < v.size(); i++) {
      ll = L[v[i]], rr = R[v[i]];
      if (ll < l) swap(ll, l), swap(rr, r);
      if (r < ll) {
        l = n + 1;
        break;
      }
      l = ll, r = min(r, rr);
    }
    if (l == n + 1) continue;
    int c = g[cnt][r] - g[cnt][l - 1], t = __builtin_popcount(S);
    if (c < 0) c += P;
    if (t & 1)
      sub(ans, c);
    else
      add(ans, c);
  }
  printf("%d", ans);
}
