#include <bits/stdc++.h>
using namespace std;
int N, M;
int L[303030], R[303030];
int A[21], B[21];
int S[303030];
int T[303030];
int sel[303030];
signed long long num[303030][41];
const signed long long mo = 998244353;
signed long long comb(signed long long N_, signed long long C_) {
  const int NUM_ = 400001;
  static signed long long fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
  if (fact[0] == 0) {
    inv[1] = fact[0] = factr[0] = 1;
    for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
    for (int i = 1; i <= NUM_; ++i)
      fact[i] = fact[i - 1] * i % mo, factr[i] = factr[i - 1] * inv[i] % mo;
  }
  if (N_ < 0 || C_ < 0 || C_ > N_) return 0;
  return factr[C_] * fact[N_] % mo * factr[N_ - C_] % mo;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> M;
  for (i = 0; i < (N); i++) cin >> L[i] >> R[i];
  for (i = 0; i < (M); i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  for (i = 0; i < (N); i++)
    if (S[i] == 0) {
      T[L[i]]++;
      T[R[i] + 1]--;
    }
  for (i = 1; i <= N; i++) {
    T[i] += T[i - 1];
    for (j = 0; j < (41); j++) {
      num[i][j] = (comb(T[i] - j, i - j) + num[i - 1][j]) % mo;
    }
  }
  signed long long ret = 0;
  int mask;
  for (mask = 0; mask < (1 << M); mask++) {
    int TL = 1, TR = N, del = 0;
    for (i = 0; i < (M); i++)
      if (mask & (1 << i)) {
        if (sel[A[i]] == 0) {
          del++;
          sel[A[i]]++;
          TL = max(TL, L[A[i]]);
          TR = min(TR, R[A[i]]);
        }
        if (sel[B[i]] == 0) {
          del++;
          sel[B[i]]++;
          TL = max(TL, L[B[i]]);
          TR = min(TR, R[B[i]]);
        }
      }
    TL = max(TL, del);
    if (TL <= TR) {
      signed long long tmp = num[TR][del] - num[TL - 1][del];
      if (__builtin_popcount(mask) % 2 == 1) {
        ret -= tmp;
      } else {
        ret += tmp;
      }
    }
    for (i = 0; i < (M); i++) sel[A[i]] = sel[B[i]] = 0;
  }
  cout << (ret % mo + mo) % mo << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
