#include <bits/stdc++.h>
using namespace std;
long long dp[2 * 100000];
int main(void) {
  int grid_cnt;
  int section_cnt;
  unordered_map<int, bool> steps;
  cin >> grid_cnt >> section_cnt;
  for (int i = 0; i < section_cnt; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      steps[j] = true;
    }
  }
  dp[0] = 1;
  for (int i = 1; i < 2 * 100000; i++) {
    dp[i] = 0;
  }
  for (int i = 0; i < grid_cnt; i++) {
    for (auto st = steps.begin(); st != steps.end(); st++) {
      if (i + st->first < 2 * 100000) {
        dp[i + st->first] += dp[i];
        dp[i + st->first] %= 998244353;
      }
    }
  }
  cout << dp[grid_cnt - 1] << endl;
  return 0;
}
