#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long inf = 1e18;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<long long> f(n + 5), a(n + 5);
  vector<bool> num(n + 5);
  for (int i = 0; i < (k); i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) num[j] = true;
  }
  a[0] = 0;
  f[0] = 0;
  for (int i = 1; i < (n); i++) {
    if (num[i]) {
      a[i]++;
      a[i + 1]--;
    }
    f[i] = f[i - 1] + a[i];
    f[i] %= mod;
    for (int j = 0; j < (k); j++) {
      a[i + l[j]] += f[i];
      a[i + l[j]] %= mod;
      a[i + r[j] + 1] -= f[i];
      a[i + r[j] + 1] = (a[i + r[j] + 1] + mod) % mod;
    }
  }
  cout << f[n - 1] << endl;
  return 0;
}
