#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 998244353;
struct M {
  unsigned v;
  M(long long a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
  M& operator+=(M r) {
    if ((v += r.v) >= mod) v -= mod;
    return *this;
  }
  M& operator-=(M r) {
    if ((v += mod - r.v) >= mod) v -= mod;
    return *this;
  }
  M& operator*=(M r) {
    v = (uint64_t)v * r.v % mod;
    return *this;
  }
};
uint32_t add(M a, M b) { return (a += b).v; }
uint32_t mul(M a, M b) { return (a *= b).v; }
uint32_t sub(M a, M b) { return (a -= b).v; }
const int N = 4e5 + 3;
M lazy[N << 2];
M tree[N << 2];
struct segtree {
  M combine(M a, M b) { return add(a, b); }
  void prop(int l, int r, int x) {
    if (lazy[x].v) {
      tree[x] += lazy[x].v;
      if (l ^ r) {
        int lc = x + x, rc = lc + 1;
        lazy[lc].v += lazy[x].v;
        lazy[rc].v += lazy[x].v;
      }
      lazy[x].v = 0;
    }
  }
  void update(int l, int r, int ql, int qr, M val, int x) {
    prop(l, r, x);
    if (qr < l || r < ql) {
      return;
    }
    if (ql <= l && r <= qr) {
      lazy[x] = val;
      prop(l, r, x);
      return;
    }
    int mid = l + r >> 1, lc = x + x, rc = lc + 1;
    update(l, mid, ql, qr, val, lc);
    update(mid + 1, r, ql, qr, val, rc);
    tree[x] = combine(tree[lc], tree[rc]);
  }
  M query(int l, int r, int ql, int qr, int x) {
    prop(l, r, x);
    if (qr < l || r < ql) {
      return 0;
    }
    if (ql <= l and r <= qr) {
      prop(l, r, x);
      return tree[x];
    }
    int mid = l + r >> 1, lc = x + x, rc = lc + 1;
    return combine(query(l, mid, ql, qr, lc), query(mid + 1, r, ql, qr, rc));
  }
};
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> q(k);
  for (auto& [x, y] : q) {
    cin >> x >> y;
  }
  segtree ins;
  const int N = ::N - 1;
  ins.update(1, N, 1, 1, 1, 1);
  for (int i = 1; i < n; ++i) {
    M cur = ins.query(1, N, i, i, 1);
    for (auto [l, r] : q) {
      l += i;
      r += i;
      ins.update(1, N, l, r, cur, 1);
    }
  }
  cout << ins.query(1, N, n, n, 1).v << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
