#include <bits/stdc++.h>
using namespace std;
long long f[200100];
int s[200100] = {}, cnt = 0;
int main() {
  int n, m;
  cin >> n >> m;
  f[1] = 1;
  for (int i = 1; i <= m; i++) {
    int p, q;
    cin >> p >> q;
    for (int j = p; j <= q; j++) {
      s[++cnt] = j;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= cnt; j++) {
      if (i - s[j] <= 0)
        continue;
      else
        f[i] = ((f[i] % 998244353) + (f[i - s[j]] % 998244353) % 998244353);
    }
  }
  cout << f[n] % 998244353;
  return 0;
}
