#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, i, j, ii, jj, zx, xc,
    mod = 998244353LL, fct[300009], lf[300009], rg[300009], l, r, fc[300009], z,
    x, kl[300009][42], k[300009], fx[300009], pas;
pair<long long, long long> p[300009];
long long xar(long long q, long long w) {
  if (w == 0) return 1LL;
  long long qw = xar(q, w / 2);
  if (w % 2 == 0)
    return (qw * qw) % mod;
  else
    return ((qw * qw) % mod * q) % mod;
}
long long dv(long long q, long long w) { return (q * xar(w, mod - 2)) % mod; }
long long C(long long q, long long w) {
  return (fct[q] * (fc[w] * fc[q - w] % mod)) % mod;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a >> b;
  for (i = 1; i <= a; i++) {
    cin >> lf[i] >> rg[i];
    k[lf[i]]++;
    k[rg[i] + 1]--;
  }
  for (i = 1; i <= a; i++) {
    k[i] += k[i - 1];
  }
  for (i = 0; i < b; i++) {
    cin >> p[i].first >> p[i].second;
  }
  fct[0] = 1;
  fc[0] = dv(1, fct[0]);
  for (i = 1; i <= a + 2; i++) {
    fct[i] = fct[i - 1] * i;
    fct[i] %= mod;
    fc[i] = dv(1, fct[i]);
  }
  for (i = 1; i <= a; i++) {
    zx = min(min(k[i], i), 2 * b);
    for (x = 0; x <= zx; x++) {
      kl[i][x] = C(k[i] - x, i - x);
    }
  }
  for (i = 1; i <= a; i++) {
    for (x = 0; x <= 2 * b; x++) {
      kl[i][x] += kl[i - 1][x];
      kl[i][x] %= mod;
    }
  }
  pas = kl[a][0];
  for (i = 1; i < (1 << b); i++) {
    l = 0;
    r = a + 1;
    x = 0;
    for (j = 0; j < b; j++) {
      if (((1 << j) & i) != 0) {
        if (fx[p[j].first] != i) {
          fx[p[j].first] = i;
          x++;
        }
        if (fx[p[j].second] != i) {
          fx[p[j].second] = i;
          x++;
        }
        if (l < lf[p[j].first]) l = lf[p[j].first];
        if (r > rg[p[j].first]) r = rg[p[j].first];
        if (l < lf[p[j].second]) l = lf[p[j].second];
        if (r > rg[p[j].second]) r = rg[p[j].second];
      }
    }
    if (l < x) l = x;
    if (l > r) continue;
    zx = kl[r][x] - kl[l - 1][x] + mod;
    zx %= mod;
    if (__builtin_popcount(i) % 2 == 0) {
      pas = (pas + zx) % mod;
    } else {
      pas = (pas - zx + mod) % mod;
    }
  }
  cout << pas;
  return 0;
}
