#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long nm = 0;
  bool fh = true;
  char cw = getchar();
  for (; !isdigit(cw); cw = getchar()) fh ^= (cw == '-');
  for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0');
  return fh ? nm : -nm;
}
namespace CALC {
inline int add(int x, int y) {
  return (x + y >= 998244353) ? (x + y - 998244353) : (x + y);
}
inline int mns(int x, int y) {
  return (x - y < 0) ? (x - y + 998244353) : (x - y);
}
inline int mul(long long x, long long y) { return x * y % 998244353; }
inline void upd(int &x, int y) {
  x = (x + y >= 998244353) ? (x + y - 998244353) : (x + y);
}
inline void dec(int &x, int y) {
  x = (x - y < 0) ? (x - y + 998244353) : (x - y);
}
inline int qpow(int x, long long sq) {
  int res = 1;
  for (; sq; sq >>= 1, x = mul(x, x))
    if (sq & 1) res = mul(res, x);
  return res;
}
}  // namespace CALC
using namespace CALC;
int n, m, fac[300200], ifac[300200], sm[300200][42], ans;
int l[300200], r[300200], ct[300200], hv, L, R;
pair<int, int> a[300200];
vector<int> clr;
bool f[300200];
inline int C(int x, int y) {
  if (x < 0 || y < 0 || x < y) return 0;
  return mul(fac[x], mul(ifac[y], ifac[x - y]));
}
inline void _ins(int x) {
  if (f[x]) return;
  f[x] = true, clr.push_back(x), ++hv, L = max(L, l[x]), R = min(R, r[x]);
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 300000; i++) fac[i] = mul(fac[i - 1], i);
  ifac[300000] = qpow(fac[300000], 998244353 - 2);
  for (int i = 300000 - 1; ~i; --i) ifac[i] = mul(ifac[i + 1], i + 1);
  n = read(), m = read();
  for (int i = 1; i <= n; i++)
    l[i] = read(), r[i] = read(), ct[l[i]]++, --ct[r[i] + 1];
  for (int i = 1; i <= m; i++) a[i].first = read(), a[i].second = read();
  for (int i = 1; i <= n; i++) ct[i] += ct[i - 1];
  for (int k = 0; k <= 40; k++)
    for (int i = 1; i <= n; i++)
      sm[i][k] = add(sm[i - 1][k], C(ct[i] - k, i - k));
  for (int s = 0; s < (1 << m); s++) {
    L = 1, R = n, clr.clear(), hv = 0;
    for (int i = 1; i <= m; i++)
      if (s & (1 << i - 1)) _ins(a[i].first), _ins(a[i].second);
    for (int i = 0, TP = clr.size(); i < TP; i++) f[clr[i]] = false;
    if (L > R) continue;
    int rem = mns(sm[R][hv], sm[L - 1][hv]);
    if (__builtin_popcount(s) & 1)
      dec(ans, rem);
    else
      upd(ans, rem);
  }
  printf("%d\n", ans);
  return 0;
}
