#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 3e5 + 5;
int n, m, l[N], r[N], a[N], b[N];
long long ans, fac[N], inv[N], sum[N][41];
struct Seg {
  int val, tag;
} t[N << 2];
void push_down(int o, int l, int r) {
  int ls = o << 1, rs = o << 1 | 1;
  t[ls].tag += t[o].tag, t[rs].tag += t[o].tag;
  int mid = (l + r) >> 1;
  t[ls].val += (mid - l + 1) * t[o].tag;
  t[rs].val += (r - mid) * t[o].tag;
  t[o].tag = 0;
}
int query(int o, int l, int r, int x) {
  if (l == r) return t[o].val;
  int mid = (l + r) >> 1;
  push_down(o, l, r);
  if (x <= mid)
    return query(o << 1, l, mid, x);
  else
    return query(o << 1 | 1, mid + 1, r, x);
}
void update(int o, int l, int r, int x, int y, int k) {
  if (x <= l && r <= y) {
    t[o].val += (r - l + 1) * k;
    t[o].tag += k;
    return;
  }
  push_down(o, l, r);
  int mid = (l + r) >> 1;
  if (x <= mid) update(o << 1, l, mid, x, y, k);
  if (mid < y) update(o << 1 | 1, mid + 1, r, x, y, k);
  t[o].val = t[o << 1].val + t[o << 1 | 1].val;
}
long long Ksm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return res;
}
long long cal(int n, int k) {
  if (n < k || min(n, k) < 0) return 0;
  return fac[n] * inv[k] % mod * inv[n - k] % mod;
}
int get(int s) {
  int f = 0;
  for (register int i = 0; i <= 27; i++)
    if (s & (1 << i)) f++;
  return f;
}
map<int, int> M;
int work(int s) {
  M.clear();
  int ans = 0;
  for (register int i = 0; i <= 27; i++)
    if (s & (1 << i)) {
      if (!M[a[i + 1]]) ans++, M[a[i + 1]] = 1;
      if (!M[b[i + 1]]) ans++, M[b[i + 1]] = 1;
    }
  return ans;
}
struct node {
  int l, r;
  bool operator==(const node &rhs) const { return l == rhs.l && r == rhs.r; }
} p[1 << 21];
void merge(node &a, node b) {
  a.l = max(a.l, b.l);
  a.r = min(a.r, b.r);
}
int main() {
  cin >> n >> m;
  for (register int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    update(1, 1, n, l[i], r[i], 1);
  }
  fac[0] = inv[0] = 1;
  for (register int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % mod, inv[i] = Ksm(fac[i], mod - 2);
  for (register int i = 1; i <= n; i++) {
    ans = (ans + cal(query(1, 1, n, i), i)) % mod;
    for (register int j = 0; j <= 40; j++)
      sum[i][j] = (sum[i - 1][j] + cal(query(1, 1, n, i) - j, i - j)) % mod;
  }
  for (register int i = 1; i <= m; i++) cin >> a[i] >> b[i];
  int S = (1 << m) - 1;
  p[0].l = 1, p[0].r = n;
  for (register int i = 1; i <= S; i++) {
    int f = get(i) & 1 ? -1 : 1;
    int siz = work(i);
    node tmp;
    bool fir = true;
    for (register int j = 27; j >= 0; j--)
      if (i & (1 << j)) {
        int t = i ^ (1 << j);
        p[i] = p[t];
        merge(p[i], (node){l[a[j + 1]], r[a[j + 1]]});
        merge(p[i], (node){l[b[j + 1]], r[b[j + 1]]});
        if (fir) {
          fir = false;
          tmp = p[i];
        } else
          assert(tmp == p[i]);
        if (p[i].l > p[i].r) break;
        ans =
            (ans + 1ll * f * (sum[p[i].r][siz] - sum[p[i].l - 1][siz]) % mod) %
            mod;
        break;
      }
  }
  cout << (ans + mod) % mod << endl;
}
