#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> d;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) d.push_back(j);
  }
  sort(d.begin(), d.end());
  vector<long long> dp(N + 1);
  dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < (int)d.size(); j++) {
      if (i - d[j] < 1) break;
      dp[i] = (dp[i] + dp[i - d[j]]) % 998244353;
    }
  }
  cout << dp[N] << endl;
  return 0;
}
