#include <bits/stdc++.h>
using namespace std;
using p = pair<int, int>;
const long long mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  int q = 0;
  for (int m = 0; m < (k); m++) {
    int l, r;
    cin >> l >> r;
    for (int o = l; o < r; o++) {
      a[q] = o;
      q++;
    }
  }
  int g = a.size();
  int coun = 0;
  for (int s = 0; s < (1 << g); s++) {
    int sum = 0;
    for (int i = 0; i < g; i++) {
      if ((s >> i) & 1) {
        sum += a[i];
      }
    }
    if (sum == n - 1) {
      coun++;
      coun = coun % mod;
    }
  }
  cout << coun << endl;
}
