#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
long long rnd() {
  unsigned long long ans = 0;
  for (int i = (int)(0); i <= (int)(4); i++) ans = ans << 15 ^ rand();
  return ans % ((unsigned long long)1 << 63);
}
const int N = 300005, mod = 998244353, K = 42;
long long s[K][N], fac[N], ni[N], ans;
int n, m, vis[N], x[K / 2], y[K / 2], l[N], r[N], f[N];
long long ksm(long long a, int b) {
  int ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long c(int a, int b) {
  return a >= b && b >= 0 ? fac[a] * ni[b] % mod * ni[a - b] % mod : 0;
}
void dfs(int p, int dq, int zt, int L, int R) {
  if (L > R) return;
  if (p > m) {
    ans = (ans + zt * (s[dq][R] - s[dq][L - 1])) % mod;
    return;
  }
  dfs(p + 1, dq, zt, L, R);
  if (!vis[x[p]]) dq++;
  vis[x[p]]++;
  if (!vis[y[p]]) dq++;
  vis[y[p]]++;
  dfs(p + 1, dq, -zt, max(L, max(l[x[p]], l[y[p]])),
      min(R, min(r[x[p]], r[y[p]])));
  vis[x[p]]--;
  vis[y[p]]--;
}
int main() {
  n = read();
  m = read();
  for (int i = (int)(fac[0] = 1); i <= (int)(n); i++)
    fac[i] = fac[i - 1] * i % mod;
  ni[n] = ksm(fac[n], mod - 2);
  for (int i = (int)(n); i >= (int)(1); i--) ni[i - 1] = ni[i] * i % mod;
  for (int i = (int)(1); i <= (int)(n); i++) {
    l[i] = read();
    r[i] = read();
    f[l[i]]++;
    f[r[i] + 1]--;
  }
  for (int i = (int)(1); i <= (int)(n); i++) f[i] += f[i - 1];
  for (int o = (int)(0); o <= (int)(40); o++) {
    for (int i = (int)(1); i <= (int)(n); i++)
      s[o][i] = (s[o][i - 1] + c(f[i] - o, i - o)) % mod;
  }
  for (int i = (int)(1); i <= (int)(m); i++) {
    x[i] = read();
    y[i] = read();
  }
  dfs(1, 0, 1, 1, n);
  cout << (ans + mod) % mod << endl;
}
