#include <bits/stdc++.h>
using namespace std;
using INT = long long;
const int mod = 998244353;
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int l[300100], r[300100], u[300100], v[300100];
int b[300100];
int sum[300100][44], fac[300100], rev[300100];
int L[300100], R[300100];
void pre() {
  fac[0] = 1;
  for (int i = 1; i < 300100; i++) fac[i] = (INT)fac[i - 1] * i % mod;
  rev[300100 - 1] = power(fac[300100 - 1], mod - 2, mod);
  for (int i = 300100 - 2; i >= 0; i--)
    rev[i] = (INT)rev[i + 1] * (i + 1) % mod;
}
int _C(int n, int k) {
  if (n < k) return 0;
  return (INT)fac[n] * rev[k] % mod * rev[n - k] % mod;
}
void add(int u, int x) {
  for (; u < 300100; u += u & -u) b[u] += x;
}
int calc(int u, int ans = 0) {
  for (; u; u -= u & -u) ans += b[u];
  return ans;
}
int solve(int l, int r, int x) {
  int ans = (sum[r][x] - sum[l - 1][x]) % mod;
  ans = (ans + mod) % mod;
  return ans;
}
int main() {
  pre();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &L[i], &R[i]);
    add(L[i], 1);
    add(R[i] + 1, -1);
  }
  for (int i = 0; i < m; i++) scanf("%d %d", &u[i], &v[i]);
  int mx = (1 << m);
  int nn = 2 * m;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= nn; j++) sum[i][j] = sum[i - 1][j];
    int tot = calc(i);
    for (int j = 0; j <= min(i, nn); j++)
      sum[i][j] = (sum[i][j] + _C(tot - j, i - j)) % mod;
  }
  int ans = 0;
  for (int i = 0; i < mx; i++) {
    int st = 1, ed = n, sg = 1;
    int ct = __builtin_popcount(i);
    if (ct & 1) sg = -1;
    vector<int> vec;
    for (int j = 0; j < m; j++) {
      if ((i & (1 << j))) {
        st = max(st, L[u[j]]);
        st = max(st, L[v[j]]);
        ed = min(ed, R[u[j]]);
        ed = min(ed, R[v[j]]);
        vec.push_back(u[j]);
        vec.push_back(v[j]);
      }
    }
    if (st > ed) continue;
    sort(vec.begin(), vec.end());
    vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
    st = max(st, (int)vec.size());
    if (st > ed) continue;
    ans = (ans + sg * solve(st, ed, vec.size())) % mod;
  }
  ans = (ans + mod) % mod;
  cout << ans << endl;
  return 0;
}
