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