#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int del[200004], cur;
int n, K, d[200004];
pair<int, int> p[20];
int fr(int r, int l) {
  if (r < 1) return 0;
  if (l < 1) l = 1;
  return (d[r] - d[l - 1] + MOD) % MOD;
}
int main() {
  cin >> n >> K;
  for (int i = 0; i < K; i++) cin >> p[i].first >> p[i].second;
  sort(p, p + K);
  for (int i = 1; i < K; i++) {
    if (p[i - 1].second >= p[i].first) p[i].first = p[i].second + 1;
  }
  d[1] = 1;
  for (int i = 2; i <= n; i++) {
    d[i] = d[i - 1];
    for (int j = 0; j < K; j++)
      if (p[j].first <= p[j].second)
        d[i] = (d[i] + fr(i - p[j].first, i - p[j].second)) % MOD;
  }
  cout << d[n] - d[n - 1];
}
