#include <bits/stdc++.h>
using namespace std;
template <typename X, typename M>
struct SegTreeLazyProportional {
  using FX = function<X(X, X)>;
  using FA = function<X(X, M)>;
  using FM = function<M(M, M)>;
  using FP = function<M(M, int)>;
  int n;
  FX fx;
  FA fa;
  FM fm;
  FP fp;
  const X ex;
  const M em;
  vector<X> dat;
  vector<M> lazy;
  SegTreeLazyProportional(int n_, FX fx_, FA fa_, FM fm_, FP fp_, X ex_, M em_)
      : n(),
        fx(fx_),
        fa(fa_),
        fm(fm_),
        fp(fp_),
        ex(ex_),
        em(em_),
        dat(n_ * 4, ex),
        lazy(n_ * 4, em) {
    int x = 1;
    while (n_ > x) x *= 2;
    n = x;
  }
  void set(int i, X x) { dat[i + n - 1] = x; }
  void build() {
    for (int k = n - 2; k >= 0; k--)
      dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
  }
  void eval(int k, int len) {
    if (lazy[k] == em) return;
    if (k < n - 1) {
      lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]);
    }
    dat[k] = fa(dat[k], fp(lazy[k], len));
    lazy[k] = em;
  }
  void update(int a, int b, M x, int k, int l, int r) {
    eval(k, r - l);
    if (a <= l && r <= b) {
      lazy[k] = fm(lazy[k], x);
      eval(k, r - l);
    } else if (a < r && l < b) {
      update(a, b, x, k * 2 + 1, l, (l + r) / 2);
      update(a, b, x, k * 2 + 2, (l + r) / 2, r);
      dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  void update(int a, int b, M x) { update(a, b, x, 0, 0, n); }
  X query_sub(int a, int b, int k, int l, int r) {
    eval(k, r - l);
    if (r <= a || b <= l) {
      return ex;
    } else if (a <= l && r <= b) {
      return dat[k];
    } else {
      X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return fx(vl, vr);
    }
  }
  X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};
int main() {
  int n, k;
  cin >> n >> k;
  using X = long long;
  using M = long long;
  auto fx = [](X x1, X x2) -> X { return (x1 + x2) % 998244353; };
  auto fa = [](X x, M m) -> X { return (x + m) % 998244353; };
  auto fm = [](M m1, M m2) -> M { return (m1 + m2) % 998244353; };
  auto fp = [](M m, long long n) -> M { return (m * n) % 998244353; };
  long long ex = 0;
  long long em = 0;
  SegTreeLazyProportional<X, M> rmq(n, fx, fa, fm, fp, ex, em);
  for (int i = 0; i < n; i++) {
    rmq.set(i, 0);
  }
  rmq.set(0, 1);
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int j = 0; j < n; j++) {
    for (int m = 0; m < k; m++) {
      int l2 = l[m] + j;
      if (l2 >= n) break;
      int r2 = r[m] + j;
      if (r2 >= n) r2 = n - 1;
      int nn = rmq.query(j, j + 1);
      if (nn != 0) {
        rmq.update(l2, r2 + 1, nn);
      }
    }
  }
  cout << rmq.query(n - 1, n) << endl;
}
