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