#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
int main() {
  int n, k;
  cin >> n >> k;
  VI l(k), r(k), list;
  VLL dp(n + 10, 0);
  for (int i = (0); i < (k); i++) {
    cin >> l[i] >> r[i];
    for (int j = (l[i]); j < (r[i] + 1); j++) {
      list.push_back(j);
      dp[j + 1]++;
    }
  }
  for (int i = (0); i < (n); i++) {
    for (int x : list) {
      if (i + x <= n) {
        dp[i + x] += dp[i];
        dp[i + x] %= 998244353;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
