#include <bits/stdc++.h>
using namespace std;
int n, m, A[25], B[25];
long long ans;
vector<int> vec[300010], hate[300010];
int cnt[25], people[1 << 20];
long long k[45];
int ONES[1 << 20];
long long FAC[300010], INV[300010];
long long power(long long a, long long b) {
  long long base = a, y = 1;
  for (; b; b >>= 1) {
    if (b & 1) y = y * base % 998244353;
    base = base * base % 998244353;
  }
  return y;
}
void gao(int b, int c, int d, int e) {
  if (c >= m) {
    k[people[d]] += ONES[d] & 1 ? -e : e;
    return;
  }
  if (b >> c & 1) gao(b, c + 1, d | (1 << c), e);
  gao(b, c + 1, d, e);
}
int main() {
  int i, j, l, r, x, y;
  scanf("%d%d", &n, &m);
  for (i = (1 << m) - 1; i >= 0; i--)
    for (j = 0; j < m; j++) ONES[i] += i >> j & 1;
  for (i = 1, FAC[0] = INV[0] = 1; i <= n; i++)
    FAC[i] = FAC[i - 1] * i % 998244353, INV[i] = power(FAC[i], 998244353 - 2);
  for (i = 1; i <= n; i++)
    scanf("%d%d", &l, &r), vec[l].push_back(i), vec[r + 1].push_back(-i);
  for (i = 0; i < m; i++)
    scanf("%d%d", &A[i], &B[i]), hate[A[i]].push_back(i),
        hate[B[i]].push_back(i);
  for (i = (1 << m) - 1; i >= 0; i--) {
    vector<int> p;
    for (j = 0; j < m; j++)
      if (i >> j & 1) p.push_back(A[j]), p.push_back(B[j]);
    people[i] =
        (sort(p.begin(), p.end()), unique(p.begin(), p.end()) - p.begin());
  }
  for (i = 1, x = y = 0; i <= n; i++) {
    for (int a : vec[i])
      if (a > 0) {
        x++;
        for (int b : hate[a]) {
          cnt[b]++;
          if (cnt[b] == 2) gao(y, 0, 1 << b, 1), y |= (1 << b);
        }
      }
    for (int a : vec[i])
      if (a < 0) {
        x--;
        for (int b : hate[-a]) {
          cnt[b]--;
          if (cnt[b] == 1) y &= ~(1 << b), gao(y, 0, 1 << b, -1);
        }
      }
    k[0] = 1;
    for (j = 0; j <= m * 2; j++) {
      int a = x - j, b = i - j;
      if (a < 0 || b < 0 || a < b) break;
      ans = (ans + (k[j] + 998244353) % 998244353 * FAC[a] % 998244353 *
                       INV[b] % 998244353 * INV[a - b] % 998244353) %
            998244353;
    }
  }
  printf("%lld", ans);
  return 0;
}
