#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long MOD = 998244353;
vector<ll> dp;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> allow;
  for (long long i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      allow.push_back(j);
    }
  }
  dp.resize(n + 1, 0);
  sort(allow.begin(), allow.end());
  dp.at(1) = 1;
  for (long long i = 1; i <= n; i++) {
    if (dp.at(i) == 0) {
      continue;
    }
    cout << i << endl;
    auto it = upper_bound(allow.begin(), allow.end(), n - i);
    for (long long j = 0; j < distance(allow.begin(), it); j++) {
      if (i + allow.at(j) <= n) {
        dp.at(i + allow.at(j)) += dp.at(i);
        dp.at(i + allow.at(j)) %= MOD;
      }
    }
  }
  cout << dp.at(n) << endl;
}
