#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(n), r(n);
  for (int i = 0; i < (k); i++) cin >> l[i] >> r[i];
  vector<long long> dp(n + 1);
  vector<long long> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (k); j++) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] %= 998244353;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= 998244353;
    if (dpsum[i] < 0) dpsum[i] += 998244353;
  }
  cout << dp[n] << endl;
  return 0;
}
