#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll MOD = 998244353;
  int N, K;
  cin >> N >> K;
  vector<int> kukan(N + 1, 0);
  int l, r;
  for (int i = 0; i < K; ++i) {
    cin >> l >> r;
    l;
    r;
    for (int j = l; j <= r; ++j) kukan.at(j) = 1;
  }
  ll DP[200000] = {};
  DP[0] = 1;
  for (int i = 1; i < N; ++i) {
    for (int j = 1; j <= i; ++j) {
      if (kukan.at(j) == 0) continue;
      DP[i] += DP[i - j];
    }
    DP[i] %= MOD;
  }
  cout << DP[N - 1] << endl;
  return 0;
}
