#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> dp(n + 1);
  vector<int> 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;
  }
  cout << dp[n] << endl;
  return 0;
}
