#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
std::ostream& operator<<(std::ostream& out, const std::pair<S, T>& a) {
  std::cout << '(' << a.first << ", " << a.second << ')';
  return out;
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
  std::cout << '[';
  for (ll i = (0); i < (a.size()); ++i) {
    std::cout << a[i];
    if (i != a.size() - 1) std::cout << ", ";
  }
  std::cout << ']';
  return out;
}
const ll mod = 998244353;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
struct combination {
  std::vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
ll n, m;
ll l[300010], r[300010];
ll a[30], b[30];
ll cnt[300010];
mint binom[50][300010];
combination comb(300010);
int main() {
  std::cin >> n >> m;
  for (ll i = (0); i < (n); ++i) {
    std::cin >> l[i] >> r[i];
    ++cnt[l[i]];
    --cnt[r[i] + 1];
  }
  for (ll i = (0); i < (n + 1); ++i) cnt[i + 1] += cnt[i];
  for (ll i = (0); i < (m); ++i) std::cin >> a[i] >> b[i];
  for (ll i = (1); i < (n + 1); ++i) {
    for (ll j = (0); j < (2 * m + 1); ++j) {
      binom[j][i] = binom[j][i - 1] + comb(cnt[i] - j, i - j);
    }
  }
  mint ans = 0;
  for (ll i = (0); i < (1ll << m); ++i) {
    ll L = 1, R = n;
    std::set<ll> S;
    for (ll j = (0); j < (m); ++j)
      if (i >> j & 1) {
        S.emplace(a[j] - 1);
        S.emplace(b[j] - 1);
      }
    ll k = __builtin_popcountll(i);
    for (auto x : S) {
      chmax(L, l[x]);
      chmin(R, r[x]);
    }
    if (R >= L) {
      ans += (binom[S.size()][R] - binom[S.size()][L - 1]) * (k & 1 ? -1 : 1);
    }
  }
  std::cout << ans.x << '\n';
  return 0;
}
