#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long n, k;
  cin >> n >> k;
  int r[n + 1];
  memset(r, 0, sizeof(r));
  while (k--) {
    long x, y;
    cin >> x >> y;
    r[x] = 1;
    r[y] = -1;
  }
  map<long, long> m;
  for (long i = 1; i <= n; i++) {
    if (r[i] == 1) {
      while (i <= n && r[i] != -1) {
        r[i++] = 1;
      }
      r[i] = 1;
    }
  }
  for (long i = 1; i <= n; i++)
    if (r[i]) m[i] = 1;
  long long p[n + 1];
  memset(p, 0, sizeof(p));
  p[1] = 1;
  for (long i = 2; i <= n; i++) {
    for (auto it : m) {
      if (i - it.first > 0 && p[i - it.first] != 0)
        p[i] = (p[i] + p[i - it.first]) % 998244353;
    }
  }
  cout << p[n];
  return 0;
}
