#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 998244353;
int64_t a[1000005];
int64_t d[2000005];
signed main() {
  int64_t n, k;
  int64_t l, r;
  int64_t b = 0, c = 1;
  vector<int64_t> q;
  cin >> n >> k;
  for (int64_t i = 0; i < k; i++) {
    cin >> l >> r;
    a[l]++;
    a[r + 1]--;
  }
  for (int64_t i = 1; i <= n; i++) {
    b += a[i];
    if (b > 0) q.push_back(i);
  }
  d[1] = 1;
  sort(q.begin(), q.end());
  for (int64_t i = 2; i <= n; i++) {
    for (int64_t j = 0; j < q.size(); j++) {
      if (i - q[j] > 0) {
        d[i] += d[i - q[j]];
        d[i] %= mod;
      } else
        break;
    }
  }
  cout << d[n] << "\n";
}
