#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<int> isexist_s(n + 5, 0);
  for (int i = 0; i < k; i++) {
    isexist_s[l[i]]++;
    isexist_s[r[i] + 1]--;
  }
  for (int i = 1; i < n + 5; i++) isexist_s[i] += isexist_s[i - 1];
  vector<int> move;
  for (int i = 1; i <= n; i++) {
    if (isexist_s[i]) move.push_back(i);
  }
  vector<ll> memo(n + 1, 0);
  memo[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < move.size() && i - move[j] >= 0; j++) {
      memo[i] += memo[i - move[j]];
      memo[i] %= MOD;
    }
  }
  cout << memo[n] << endl;
  return 0;
}
