#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
template <class o>
void qr(o &x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr1(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar('\n');
}
int n, m, c[N], l[N], r[N], vis[N], num;
pair<int, int> v[N];
long long jc[N], inv[N], s[N][44], ans;
long long power(long long a, long long b = mod - 2) {
  long long c = 1;
  while (b) {
    if (b & 1) c = c * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return c;
}
long long C(int x, int y) {
  return x >= y && y >= 0 ? jc[x] * inv[y] % mod * inv[x - y] % mod : 0;
}
long long F(int l, int r, int k) {
  return l > r ? 0 : (s[r][k] - s[l - 1][k]) % mod;
}
int main() {
  qr(n);
  qr(m);
  jc[0] = 1;
  for (int i = 1; i <= n; i++) jc[i] = jc[i - 1] * i % mod;
  inv[n] = power(jc[n]);
  for (int i = n; i; i--) inv[i - 1] = inv[i] * i % mod;
  for (int i = 1; i <= n; i++) qr(l[i]), qr(r[i]), c[l[i]]++, c[r[i] + 1]--;
  for (int i = 1; i <= n; i++) {
    c[i] += c[i - 1];
    ans += C(c[i], i);
    for (int j = 1; j <= 2 * m; j++)
      s[i][j] = (s[i - 1][j] + C(c[i] - j, i - j)) % mod;
  }
  for (int i = 0; i < m; i++) qr(v[i].first), qr(v[i].second);
  for (int i = (1 << m) - 1; i; i--) {
    int L = 1, R = n, cnt = 0, c = 0;
    num++;
    for (int j = 0; j < m; j++)
      if (i >> j & 1) {
        int x = v[j].first, y = v[j].second;
        L = max(L, l[x]);
        R = min(R, r[x]);
        cnt += (vis[x] != num);
        vis[x] = num;
        L = max(L, l[y]);
        R = min(R, r[y]);
        cnt += (vis[y] != num);
        vis[y] = num;
        c++;
      }
    L = max(L, cnt);
    ans += (c & 1 ? -1 : 1) * F(L, R, cnt);
  }
  pr2((ans % mod + mod) % mod);
  return 0;
}
