#include <bits/stdc++.h>
using namespace std;
void myfunc() {
  long n, k;
  cin >> n >> k;
  long tmp1, tmp2;
  vector<long> d;
  for (int i = 0; i < k; i++) {
    cin >> tmp1 >> tmp2;
    while (tmp1 <= tmp2) {
      d.push_back(tmp1);
      tmp1++;
    }
  }
  sort(d.begin(), d.end());
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  int l = d.size();
  const long long md = 998244353;
  for (long i = 2; i <= n; i++) {
    for (int j = 0; j < l && i - d[j] > 0; j++)
      dp[i] = (dp[i] + dp[i - d[j]]) % md;
  }
  cout << dp[n] << endl;
}
int main() {
  long t;
  t = 1;
  while (t--) myfunc();
  return 0;
}
