#include <bits/stdc++.h>   using namespace std;   const long long maxm = 3e5 + 5;   const long long mod = 998244353;   long long fac[maxm], inv[maxm];   long long l[maxm], r[maxm];   pair<long long, long long> p[25];   long long sum[maxm][45];   long long num[maxm];   long long n, m;   long long ppow(long long a, long long b, long long mod) {     long long ans = 1 % mod;     a %= mod;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   void init() {     fac[0] = 1;     for (long long i = 1; i < maxm; i++) fac[i] = fac[i - 1] * i % mod;     inv[maxm - 1] = ppow(fac[maxm - 1], mod - 2, mod);     for (long long i = maxm - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;   }   long long cal(long long x) {     long long ans = 0;     while (x) {       ans++;       x &= (x - 1);     }     return ans;   }   long long C(long long n, long long m) {     if (m < 0 || m > n) return 0;     return fac[n] * inv[m] % mod * inv[n - m] % mod;   }   signed main() {     ios::sync_with_stdio(0);     init();     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> l[i] >> r[i];     }     for (long long i = 0; i < m; i++) {       cin >> p[i].first >> p[i].second;     }     for (long long i = 1; i <= n; i++) {       num[l[i]]++;       num[r[i] + 1]--;     }     for (long long i = 1; i <= n; i++) {       num[i] += num[i - 1];     }     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= m * 2; j++) {         sum[i][j] = (sum[i - 1][j] + C(num[i] - j, i - j)) % mod;       }     }     long long ans = 0;     for (long long i = 0; i < (1 << m); i++) {       set<long long> s;       for (long long j = 0; j < m; j++) {         if (i >> j & 1) {           s.insert(p[j].first);           s.insert(p[j].second);         }       }       long long tot = s.size();       long long L = 1, R = n;       for (auto x : s) {         L = max(L, l[x]);         R = min(R, r[x]);       }       if (L > R) continue;       long long t = (sum[R][tot] - sum[L - 1][tot] + mod) % mod;       if (cal(i) & 1) {         ans = (ans - t + mod) % mod;       } else {         ans = (ans + t) % mod;       }     }     cout << ans << endl;     return 0;   }   