#include <bits/stdc++.h>
using namespace std;
const int N = 200010, MOD = 998244353;
long long f[N];
int s[N], m[N], n, k, l, r;
vector<int> v;
int main() {
  memset(f, 0, sizeof f);
  memset(s, 0, sizeof s);
  memset(m, 0, sizeof m);
  f[1] = 1;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      if (s[j] == 0) v.push_back(j);
      s[j] = 1;
    }
  }
  sort(v.begin(), v.end());
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size() && i - v[j] >= 1; j++) {
      f[i] += f[i - v[j]] % MOD;
    }
  }
  cout << f[n] % MOD << endl;
  return 0;
}
