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