#include <bits/stdc++.h>
using namespace std;
const int N = 300005, M = 25;
const long long p = 998244353ll;
inline long long expo(long long a, int b = 998244351) {
  long long c = 1ll;
  while (b) {
    if (b & 1) c = c * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return c;
}
long long FAC[N], IFA[N];
inline long long comb(int a, int b) {
  return (b < 0 || b > a) ? 0ll : (FAC[a] * (IFA[b] * IFA[a - b] % p) % p);
}
vector<int> L[N], R[N];
int I[N], C[M << 1];
long long E[M], ss;
inline void dfs(int m, long long a, int w = 1) {
  if (m) {
    dfs(m - 1, a, w);
    if ((ss & E[m]) == E[m]) dfs(m - 1, a & (~E[m]), -w);
  } else {
    C[__builtin_popcountll(a)] += w;
  }
}
int main() {
  int n, m, i, a, b, c = 0, f = 0, c0 = 0, c1 = 0;
  long long ans = 0ll, s1 = 0ll;
  vector<int>::iterator d;
  scanf("%d%d", &n, &m);
  FAC[0] = 1ll;
  for (i = (1); i <= (n); ++i) FAC[i] = FAC[i - 1] * i % p;
  IFA[n] = expo(FAC[n]);
  for (i = (n); i >= (1); --i) IFA[i - 1] = IFA[i] * i % p;
  for (i = (1); i <= (n); ++i) {
    scanf("%d%d", &a, &b);
    L[a].push_back(i);
    R[b].push_back(i);
  }
  for (i = (1); i <= (m); ++i) {
    scanf("%d%d", &a, &b);
    if (!I[a]) I[a] = ++c;
    if (!I[b]) I[b] = ++c;
    E[i] = (1ll << I[a]) | (1ll << I[b]);
  }
  C[0] = 1;
  for (i = (1); i <= (n); ++i) {
    for (d = L[i].begin(); d != L[i].end(); ++d) {
      a = *d;
      if (I[a]) {
        ++c1;
        f = 1;
        s1 |= 1ll << I[a];
      }
      ++c0;
    }
    if (f) {
      for (a = (0); a <= (c1); ++a) C[a] = 0;
      ss = s1;
      dfs(m, s1);
      f = 0;
    }
    for (a = (0); a <= (c1); ++a)
      ans = (ans + (C[c1 - a] + p) * comb(c0 - a, i - a)) % p;
    for (d = R[i].begin(); d != R[i].end(); ++d) {
      a = *d;
      if (I[a]) {
        --c1;
        f = 1;
        s1 ^= 1ll << I[a];
      }
      --c0;
    }
  }
  printf("%lld", ans);
  return 0;
}
