#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  long long int mod = 998244353;
  long long int n, k, i, j, l, r;
  cin >> n >> k;
  long long int a[n + 1];
  for (i = 0; i <= n; i++) a[i] = 0;
  for (i = 0; i < k; i++) {
    cin >> l >> r;
    a[l - 1] += 1;
    a[r] -= 1;
  }
  long long int now = 0;
  vector<long long int> s;
  for (i = 0; i < n; i++) {
    now += a[i];
    if (now > 0) {
      s.push_back(i + 1);
    }
  }
  long long int sizes = s.size();
  long long int ans[n];
  for (i = 0; i < n; i++) ans[i] = 0;
  ans[0] = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < sizes; j++) {
      long long int k = s[j];
      if (k + i < n) {
        ans[k + i] += ans[i];
        ans[k + i] = ans[k + i] % mod;
      }
    }
  }
  cout << ans[n - 1] << endl;
}
