#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using lb = long double;
using P = pair<ll, ll>;
using graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL << 60;
const ll mod = 998244353LL;
template <typename T>
vector<T> finv(map<ll, T> m) {
  vector<T> ret(200005);
  ret[0] = (T)1 / m[0];
  for (int i = 1; i < 200005; i++) {
    for (auto x : m) {
      if (x.second != 0 && x.first <= i && x.first != 0) {
        ret[i] = (ret[i] - x.second * ret[i - x.first]);
      }
    }
    ret[i] /= m[0];
  }
  for (int i = 0; i < (int)(200005); i++) {
    if (ret[i] < 0) ret[i] += mod;
  }
  return ret;
}
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> cnt(200005);
  for (int i = 0; i < (int)(K); i++) {
    ll l, r;
    cin >> l >> r;
    cnt[l]++;
    cnt[r + 1]--;
  }
  for (int i = 0; i < (int)(200005); i++) cnt[i] = -cnt[i];
  cnt[0]++;
  cnt[1]--;
  vector<ll> ans(200005);
  map<ll, ll> m;
  for (int i = 0; i < (int)(200005); i++) {
    if (cnt[i] != 0) m[i] = cnt[i];
  }
  ans = finv<ll>(m);
  vector<ll> anss(200005);
  for (int i = 0; i < (int)(200004); i++) {
    anss[i + 1] = ans[i];
  }
  for (int i = 0; i < (int)(200005); i++) ans[i] = (ans[i] - anss[i]) % mod;
  if (ans[N - 1] < 0) ans[N - 1] += mod;
  cout << ans[N - 1] << endl;
}
