#include <bits/stdc++.h>
using namespace std;
struct unionfind {
  vector<int> data;
  vector<int> size;
  unionfind(int n) {
    for (int i = 0; i < n; i++) {
      data.push_back(i);
      size.push_back(1);
    }
  }
  int find(int x) {
    if (data[x] == x) return x;
    return data[x] = find(data[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (size[x] > size[y]) swap(x, y);
    data[x] = y;
    size[y] += size[x];
    return true;
  }
  bool check(int x, int y) { return (find(x) == find(y)); }
  int get_size(int x) {
    int X = find(x);
    return size[X];
  }
};
int beki(long long a, long long b, int M = 998244353) {
  int x = 1;
  while (b != 0) {
    if (b & 1) {
      x = ((long long)x * a) % M;
    }
    a = ((long long)a * a) % M;
    b >>= 1;
  }
  return x;
}
int gyakugen(int a) { return beki(a, 998244353 - 2); }
struct combi {
  deque<int> kaijou;
  deque<int> kaijou_;
  combi(int n) {
    kaijou.push_back(1);
    for (int i = 1; i <= n; i++) {
      kaijou.push_back(
          ((((long long)kaijou[i - 1] * i + 998244353)) % 998244353));
    }
    int b = gyakugen(kaijou[n]);
    kaijou_.push_front(b);
    for (int i = 1; i <= n; i++) {
      int k = n + 1 - i;
      kaijou_.push_front(
          ((((long long)kaijou_[0] * k + 998244353)) % 998244353));
    }
  }
  int combination(int n, int r) {
    if (r > n) return 0;
    int a = ((((long long)kaijou[n] * kaijou_[r] + 998244353)) % 998244353);
    a = ((((long long)a * kaijou_[n - r] + 998244353)) % 998244353);
    return a;
  }
  int junretsu(int a, int b) {
    int x = ((((long long)kaijou_[a] * kaijou_[b] + 998244353)) % 998244353);
    x = ((((long long)x * kaijou[a + b] + 998244353)) % 998244353);
    return x;
  }
  int catalan(int n) {
    return ((((long long)combination(2 * n, n) * gyakugen(n + 1) + 998244353)) %
            998244353);
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(n), r(n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  vector<int> mask(n, 0);
  unionfind uf(n);
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
    mask[a[i]] |= (1 << i);
    mask[b[i]] |= (1 << i);
    uf.unite(a[i], b[i]);
  }
  vector<vector<int>> X(n, vector<int>());
  for (int i = 0; i < n; i++) {
    X[uf.find(i)].push_back(i);
  }
  vector<int> imos(n + 5, 0);
  vector<vector<vector<int>>> IMOS(0, vector<vector<int>>());
  for (int i = 0; i < n; i++) {
    if (X[i].size() == 0) continue;
    if (X[i].size() == 1) {
      imos[l[i]]++;
      imos[r[i] + 1]--;
      continue;
    }
    IMOS.push_back(vector<vector<int>>(n + 5, vector<int>(X[i].size() + 1, 0)));
    sort(X[i].begin(), X[i].end());
    for (int j = 0; j < (1 << X[i].size()); j++) {
      vector<int> inds;
      int cnt = 0;
      int now = 0;
      for (int k = 0; k < X[i].size(); k++) {
        if ((j >> k) & 1) {
          cnt++;
          inds.push_back(X[i][k]);
          if (now & mask[X[i][k]]) {
            now = -1;
            break;
          }
          now |= mask[X[i][k]];
        }
      }
      if (now == -1) continue;
      int L = 0, R = n - 1;
      for (int k = 0; k < inds.size(); k++) {
        L = max(L, l[inds[k]]);
        R = min(R, r[inds[k]]);
      }
      if (L > R) continue;
      IMOS.back()[L][cnt]++;
      IMOS.back()[R + 1][cnt]--;
    }
  }
  combi C(500000);
  for (int i = 1; i < imos.size(); i++) imos[i] += imos[i - 1];
  for (int i = 0; i < IMOS.size(); i++) {
    for (int j = 1; j < IMOS[i].size(); j++) {
      for (int k = 0; k < IMOS[i][j].size(); k++) {
        IMOS[i][j][k] += IMOS[i][j - 1][k];
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < imos.size(); i++) {
    vector<int> dp(23, 0);
    dp[0] = 1;
    for (int j = 0; j < IMOS.size(); j++) {
      vector<int> ndp(23, 0);
      for (int k = 0; k < IMOS[j][i].size(); k++) {
        int t = IMOS[j][i][k];
        for (int l = 0; l <= 22; l++) {
          if (l + k > 22) break;
          ndp[l + k] = ((((long long)ndp[l + k] +
                          ((((long long)t * dp[l] + 998244353)) % 998244353) +
                          998244353)) %
                        998244353);
        }
      }
      swap(dp, ndp);
    }
    for (int j = 0; j <= 22; j++) {
      if (j + imos[i] < i) continue;
      int t =
          ((((long long)C.combination(imos[i], i - j) * dp[j] + 998244353)) %
           998244353);
      ans = ((((long long)ans + t + 998244353)) % 998244353);
    }
  }
  cout << ans << endl;
  return 0;
}
