#include <bits/stdc++.h>
using namespace std;
long long mod = (998244353LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
void read(vector<long long> &w, long long n) {
  w.resize(n);
  for (long long i = 0; i < n; i++) cin >> w[i];
}
void print(vector<long long> &w) {
  for (long long i = 0; i < (long long)(w).size(); i++) {
    if (i == (long long)(w).size() - 1)
      cout << w[i] << "\n";
    else
      cout << w[i] << " ";
  }
}
long long prodmod(vector<long long> w);
void crivo(vector<long long> &w, long long TAM);
void inverso(vector<long long> &inv, long long TAM);
void fat_inverso(vector<long long> &inv, long long TAM);
long long choose(long long a, long long b);
void get_fat();
long long fat[300010];
long long n, m, q, k, v[300010];
long long sum[300010][100], ans;
pair<long long, long long> w[300010];
string second;
vector<long long> ini, fim;
vector<long long> invv;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<pair<long long, long long> > edge;
  fat_inverso(invv, 300010);
  for (long long i = 1; i <= n; i++) {
    cin >> w[i].first >> w[i].second;
    ini.push_back(w[i].first);
    fim.push_back(w[i].second);
  }
  for (long long i = 1, a, b; i <= m; i++) {
    cin >> a >> b;
    edge.push_back({a, b});
  }
  sort(begin(ini), end(ini));
  sort(begin(fim), end(fim));
  vector<long long> qtd(n + 1);
  long long ans = 0;
  for (long long k = 1; k <= n; k++) {
    long long A = upper_bound(begin(fim), end(fim), k - 1) -
                  lower_bound(begin(fim), end(fim), 0);
    long long B = upper_bound(begin(ini), end(ini), n + 1) -
                  lower_bound(begin(ini), end(ini), k + 1);
    A += B;
    qtd[k] = n - A;
    for (long long p = 0; p <= 40; p++) {
      sum[k][p] =
          sum[k - 1][p] + (min(qtd[k], k) < p ? 0 : choose(qtd[k] - p, k - p));
      sum[k][p] %= mod;
    }
  }
  vector<long long> caras(n + 1);
  for (long long mask = 0; mask < (1 << (long long)(edge).size()); mask++) {
    long long l = 1, r = n, p = 0;
    vector<long long> T;
    for (long long i = 0; i < (long long)(edge).size(); i++) {
      if (mask & (1 << i)) {
        l = max(l, w[edge[i].first].first);
        r = min(r, w[edge[i].first].second);
        l = max(l, w[edge[i].second].first);
        r = min(r, w[edge[i].second].second);
        if (!caras[edge[i].first]) p++;
        caras[edge[i].first] = 1;
        if (!caras[edge[i].second]) p++;
        caras[edge[i].second] = 1;
        T.push_back(edge[i].first), T.push_back(edge[i].second);
      }
    }
    for (auto w : T) caras[w] = 0;
    l = max(l, p);
    T.clear();
    if (l > r) continue;
    long long sign = (__builtin_popcount(mask) % 2 ? -1LL : 1LL);
    ans += sign * (sum[r][p] - sum[l - 1][p]);
    ans %= mod;
  }
  if (ans < 0) ans += mod;
  cout << ans << "\n";
}
long long prodmod(vector<long long> w) {
  long long curr = 1;
  for (long long i = 0; i < (long long)(w).size(); i++) {
    if (w[i] >= mod) w[i] %= mod;
    curr = (curr * w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
void get_fat() {
  if (fat[0] != 0) return;
  fat[0] = 1;
  for (long long i = 1; i < 300010; i++) fat[i] = (i * fat[i - 1]) % mod;
}
long long choose(long long a, long long b) {
  get_fat();
  if (b > a) return 0;
  if (!b) return 1;
  long long A = fat[a];
  long long B = (invv[b] * invv[a - b]) % mod;
  A = (A * B) % mod;
  return A;
}
void inverso(vector<long long> &inv, long long TAM) {
  inv.resize(TAM);
  inv[1] = inv[0] = 1;
  for (long long i = 2; i < TAM; ++i) {
    inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
  }
}
void fat_inverso(vector<long long> &inv, long long TAM) {
  inverso(inv, TAM);
  for (long long i = 2; i < TAM; i++) inv[i] = (inv[i] * inv[i - 1]) % mod;
}
void crivo(vector<long long> &w, long long TAM) {
  w.resize(TAM + 1);
  w[0] = 1;
  for (long long i = 2; i < TAM; i++)
    if (!w[i])
      for (long long j = 2 * i; j < TAM; j += i) w[j] = 1;
}
