#include <bits/stdc++.h>
using namespace std;
namespace fast {
const long long BSZ = 1 << 15;
char ibuf[BSZ];
long long ipos, ilen;
char nc() {
  if (ipos == ilen) {
    ipos = 0;
    ilen = fread(ibuf, 1, BSZ, stdin);
    if (!ilen) return EOF;
  }
  return ibuf[ipos++];
}
void rs(string &x) {
  char ch;
  while (isspace(ch = nc()))
    ;
  do {
    x += ch;
  } while (!isspace(ch = nc()) && ch != EOF);
}
template <class T>
void ri(T &x) {
  char ch;
  long long sgn = 1;
  while (!isdigit(ch = nc()))
    if (ch == '-') sgn *= -1;
  x = ch - '0';
  while (isdigit(ch = nc())) x = x * 10 + (ch - '0');
  x *= sgn;
}
template <class T, class... Ts>
void ri(T &t, Ts &...ts) {
  ri(t);
  ri(ts...);
}
char obuf[BSZ], numBuf[100];
long long opos;
void flushOut() {
  fwrite(obuf, 1, opos, stdout);
  opos = 0;
}
void wc(char c) {
  if (opos == BSZ) flushOut();
  obuf[opos++] = c;
}
void ws(string s) {
  for (char c : s) wc(c);
}
template <class T>
void wi(T x, char after = '\0') {
  if (x < 0) wc('-'), x *= -1;
  long long len = 0;
  for (; x >= 10; x /= 10) numBuf[len++] = '0' + (x % 10);
  wc('0' + x);
  for (long long i = len - 1; i >= 0; i--) wc(numBuf[i]);
  if (after) wc(after);
}
void initO() { assert(atexit(flushOut) == 0); }
}  // namespace fast
using namespace fast;
const long long mxn = 2e5 + 5, mod = 998244353;
long long n, k;
vector<pair<long long, long long>> step;
vector<long long> temp;
vector<long long> dp(mxn, -1);
long long recurse(long long N) {
  if (N == 0) return 1;
  if (dp[N] != -1) return dp[N];
  long long val = 0;
  for (auto &i : temp) {
    if (N >= i)
      val = (val + recurse(N - i)) % mod;
    else
      break;
  }
  return dp[N] = val;
}
void solve() {
  ri(n, k);
  for (long long i = 0, s, e; i < k; i++) {
    ri(s, e);
    step.emplace_back(s, e);
  }
  sort(step.begin(), step.end(),
       [](const pair<long long, long long> &p1,
          const pair<long long, long long> &p2) -> bool {
         if (p1.first == p2.first) return p1.second < p2.second;
         return p1.first < p2.first;
       });
  long long val = -1;
  temp.reserve(mxn);
  for (auto &i : step) {
    if (val == -1) {
      val = i.second;
      for (long long j = i.first; j <= val; j++) {
        temp.emplace_back(j);
      }
    } else {
      val = max(val, i.first);
      for (long long j = val; j <= i.second; j++) temp.emplace_back(j);
      val = max(val, i.second);
    }
  }
  wi(recurse(n - 1));
}
signed main() {
  initO();
  solve();
  return 0;
}
