#include <bits/stdc++.h>
using namespace std;
const long mod = 998244353;
int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A;
  set<long> B;
  for (long i = 0; i < K; i++) {
    long l, r;
    cin >> l >> r;
    for (long j = l; j <= r; j++) {
      A.push_back(j);
      B.insert(j);
    }
  }
  int l = B.size();
  vector<long> dp(N + 1, 0);
  dp.at(0) = 0;
  dp.at(1) = 1;
  for (long i = 1; i <= N; i++) {
    for (long j = 1; j <= i; j++) {
      if (B.count(j)) {
        dp.at(i) += dp.at(i - j);
        dp.at(i) %= mod;
      }
    }
  }
  cout << dp.at(N) << endl;
}
