#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 300009;   long long fac[maxn], invfac[maxn], A[33], B[33], in[maxn], idx[maxn];   vector<int> L[maxn], R[maxn];   int n, m;   long long mpw(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1ll) c = c * a % mod;       a = a * a % mod;       b >>= 1;     }     return c;   }   void init() {     fac[0] = 1;     for (int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;     invfac[maxn - 1] = mpw(fac[maxn - 1], mod - 2);     for (int i = maxn - 2; i >= 0; --i) invfac[i] = invfac[i + 1] * (i + 1) % mod;   }   long long C(int a, int b) {     if (a < b || b < 0) return 0;     return fac[a] * invfac[b] % mod * invfac[a - b] % mod;   };   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     cin >> n >> m;     vector<std::vector<int>> add(n + 1), del(n + 1);     for (int i = 1; i <= n; ++i) {       int l, r;       cin >> l >> r;       L[l].push_back(i);       R[r].push_back(i);       add[l].push_back(i - 1);       del[r].push_back(i - 1);     }     int idxtot = 0, cc = 0;     memset(idx, -1, sizeof idx);     std::vector<int> a(m), b(m);     std::vector<int> id(n, -1);     for (int i = 0; i < m; ++i) {       cin >> A[i] >> B[i];       a[i] = A[i] - 1;       b[i] = B[i] - 1;       if (idx[A[i]] == -1) idx[A[i]] = idxtot++;       if (idx[B[i]] == -1) idx[B[i]] = idxtot++;       if (id[a[i]] == -1) id[a[i]] = cc++;       if (id[b[i]] == -1) id[b[i]] = cc++;     }     init();     long long premask = 0, tot = 0, masktot = 0, curmask = 0, res = 0;     vector<long long> cnt(m + 1);     cnt[0] = 1;     std::vector<int> ways(m + 1);     std::vector<int> in2(n);     ways[0] = 1;     long long mask = 0;     int tot2 = 0, tp = 0;     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j : L[i]) {         in[j] = 1;         if (idx[j] == -1)           tot++;         else           masktot++;       }       for (auto x : add[i]) {         in2[x] = 1;         ++(id[x] == -1 ? tot2 : tp);       }       curmask = 0;       for (int j = 0; j < m; ++j) {         if (in[A[j]]) curmask |= 1ll << idx[A[j]];         if (in[B[j]]) curmask |= 1ll << idx[B[j]];       }       long long nMask = 0;       for (int j = 0; j < m; ++j) {         if (in2[a[j]]) nMask |= 1ll << id[a[j]];         if (in2[b[j]]) nMask |= 1ll << id[b[j]];       }       if (nMask != curmask) {         cout << 1 <<   n ;         return 0;       }       if (mask != premask) {         cout << 3;         return 0;       }       if (tp != masktot) {         cout << 4;         return 0;       }       if (nMask != mask) {         mask = nMask;         std::fill(ways.begin(), ways.end(), 0);         std::function<void(int, int64_t, int)> dfs1 = [&](int x, int64_t s,                                                           int coef) {           if (x == m) {             int p = __builtin_popcountll(s);             for (int j = 0; j <= m; ++j)               ways[j] = (ways[j] + 1ll * coef * C(tp - p, j - p)) % mod;             return;           }           if (in2[a[x]] && in2[b[x]])             dfs1(x + 1, s | 1ll << id[a[x]] | 1ll << id[b[x]], mod - coef);           dfs1(x + 1, s, coef);         };         dfs1(0, 0, 1);       }       if (premask != curmask) {         for (int j = 0; j <= m; ++j) cnt[j] = 0;         std::function<void(int, int64_t, int)> dfs1 = [&](int x, int64_t s,                                                           int coef) {           if (x == m) {             int p = __builtin_popcountll(s);             for (int j = 0; j <= m; ++j)               cnt[j] = (cnt[j] + 1ll * coef * C(tp - p, j - p)) % mod;             return;           }           if (in[A[x]] && in[B[x]])             dfs1(x + 1, s | 1ll << idx[A[x]] | 1ll << idx[B[x]], mod - coef);           dfs1(x + 1, s, coef);         };         dfs1(0, 0, 1);       }       premask = curmask;       for (int j = 0; j <= m; ++j)         if (cnt[j] != ways[j]) {           for (int x = 0; x < n; ++x) assert(in[x + 1] == in2[x]);           cout << 2;           return 0;         }       for (int j = 0; j <= m; ++j)         ans = (ans + 1ll * ways[j] * C(tot2, i - j)) % mod;       for (int j = 0; j <= m; ++j)         res = (res + cnt[j] * C(tot, i - j) % mod) % mod;       assert(ans == res);       for (int j : R[i]) {         in[j] = 0;         if (idx[j] == -1)           tot--;         else           masktot--;       }       for (auto x : del[i]) {         in2[x] = 0;         --(id[x] == -1 ? tot2 : tp);       }     }     cout << res;     return 0;   }