#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, M = 45;
const long long mod = 998244353;
long long fac[N], inv[N], sum[M][N];
struct node {
  int l, r;
} p[N], lim[M];
int num[N], vis[N];
long long qpow(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ans = ans * a % mod;
  return ans;
}
long long C(int n, int m) {
  if (n < m || m < 0) return 0;
  return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = qpow(fac[N - 1], mod - 2);
  for (int i = N - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &p[i].l, &p[i].r), num[p[i].l]++, num[p[i].r + 1]--;
  for (int i = 1; i <= n; i++) num[i] += num[i - 1];
  for (int i = 0; i < m; i++) scanf("%d%d", &lim[i].l, &lim[i].r);
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (i <= num[i]) ans = (ans + C(num[i], i)) % mod;
  for (int i = 0; i < M; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] = (sum[i][j - 1] + C(num[j] - i, j - i)) % mod;
  for (int i = 1; i < (1 << m); i++) {
    int l = 1, r = n, tot = 0;
    for (int j = 0; j < m; j++) {
      if (!(i & (1 << j))) continue;
      int p1 = lim[j].l, p2 = lim[j].r;
      l = max(l, max(p[p1].l, p[p2].l)), r = min(r, min(p[p1].r, p[p2].r));
      if (!vis[p1]) tot++;
      if (!vis[p2]) tot++;
      vis[p1] = vis[p2] = 1;
    }
    for (int j = 0; j < m; j++) {
      if (!(i & (1 << j))) continue;
      int p1 = lim[j].l, p2 = lim[j].r;
      vis[p1] = vis[p2] = 0;
    }
    if (l > r) continue;
    int add = __builtin_popcount(i);
    ans = (ans + (sum[tot][r] - sum[tot][l - 1] + mod) * (add % 2 ? -1 : 1) +
           mod * 5) %
          mod;
  }
  printf("%lld\n", ans);
  return 0;
}
