#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, ans = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return f * ans;
}
const long long MAXN = 3e5 + 11;
const long long MAXM = 21;
long long S[MAXN], N, L[MAXN], R[MAXN], A[MAXM], B[MAXM], Sum[MAXN][MAXM << 1],
    M;
long long fac[MAXN], ifac[MAXN], inv[MAXN], Num[MAXN], Ans;
long long C(long long a, long long b) {
  if (a < b || a < 0 || b < 0) return 0;
  return fac[a] * ifac[b] % 998244353 * ifac[a - b] % 998244353;
}
long long lowbit(long long x) { return x & -x; }
long long cont(long long x) {
  long long c = 0;
  while (x) {
    c++;
    x -= lowbit(x);
  };
  return c;
}
signed main() {
  N = read(), M = read();
  for (long long i = 1; i <= N; i++)
    L[i] = read(), R[i] = read(), S[L[i]]++, S[R[i] + 1]--;
  for (long long i = 1; i <= M; i++) A[i] = read(), B[i] = read();
  for (long long i = 1; i <= N; i++) S[i] += S[i - 1];
  fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
  for (long long i = 2; i <= N; i++)
    fac[i] = fac[i - 1] * i % 998244353,
    inv[i] = (998244353 - 998244353 / i) * inv[998244353 % i] % 998244353,
    ifac[i] = ifac[i - 1] * inv[i] % 998244353;
  for (long long i = 1; i <= N; i++) {
    for (long long j = 0; j <= 2 * M; j++) {
      Sum[i][j] = Sum[i - 1][j] + C(S[i] - j, i - j);
      Sum[i][j] %= 998244353;
    }
  }
  memset(Num, -1, sizeof(Num));
  for (long long i = 0; i < (1 << M); i++) {
    long long l = 1, r = N;
    long long cc = 0;
    for (long long j = 1; j <= M; j++)
      if (i & (1 << (j - 1))) {
        if (Num[A[j]] != i) Num[A[j]] = i, cc++;
        if (Num[B[j]] != i) Num[B[j]] = i, cc++;
        l = max(l, max(L[A[j]], L[B[j]])), r = min(r, min(R[A[j]], R[B[j]]));
      }
    if (l > r) continue;
    long long pw = ((cont(i) & 1) ? -1 : 1),
              res = (Sum[r][cc] - Sum[l - 1][cc] + 998244353) % 998244353;
    Ans += pw * res;
    Ans = ((Ans % 998244353) + 998244353) % 998244353;
  }
  printf("%lld\n", Ans);
  return 0;
}
