#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  vector<int> c(n, n + 2);
  vector<long long> a(n, 0);
  a.at(0) = 1;
  int h = 0;
  for (int i = 0; i < p; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l - 1; j < r; j++) {
      c.at(h) = j + 1;
      h++;
    }
  }
  sort(c.begin(), c.end());
  for (int i = 1; i < n; i++)
    for (int j = 0; c.at(j) <= i && j < h; j++) {
      a.at(i) += a.at(i - c.at(j));
      a.at(i) %= 998244353;
    }
  cout << a.at(n - 1) << endl;
}
