#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;
const int N = 2e5 + 5, MOD = 998244353, INF = 1e9 + 5;
int add(int x, int y) { return ((x % MOD) + (y % MOD)) % MOD; }
struct SegmentTree {
  int n;
  vector<int> t, lazy;
  void init(int x) {
    n = x;
    t.assign(n, 0);
    lazy.assign(4 * n, 0);
  }
  int merge(int x, int y) { return add(x, y); }
  void push(int i, int l, int r) {
    if (lazy[i] != 0) {
      t[i] = add(t[i], lazy[i] * (r - l + 1));
      if (l != r) {
        lazy[2 * i] = add(lazy[i], lazy[2 * i]);
        lazy[2 * i + 1] = add(lazy[i], lazy[2 * i + 1]);
      }
      lazy[i] = 0;
    }
  }
  void modify(int i, int l, int r, int ql, int qr, int val) {
    push(i, l, r);
    if (l > qr || r < ql) return;
    if (l >= ql && r <= qr) {
      lazy[i] = add(lazy[i], val);
      push(i, l, r);
      return;
    }
    int mid = (l + r) / 2;
    modify(2 * i, l, mid, ql, qr, val);
    modify(2 * i + 1, mid + 1, r, ql, qr, val);
    t[i] = merge(t[2 * i], t[2 * i + 1]);
  }
  int query(int i, int l, int r, int ql, int qr) {
    push(i, l, r);
    if (l > qr || r < ql) return 0;
    if (l >= ql && r <= qr) return t[i];
    int mid = (l + r) / 2;
    int resL = query(2 * i, l, mid, ql, qr);
    int resR = query(2 * i + 1, mid + 1, r, ql, qr);
    return merge(resL, resR);
  }
  void modify(int l, int r, int val) { modify(1, 0, n - 1, l, r, val); }
  int query(int l, int r) { return query(1, 0, n - 1, l, r); }
};
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vii segments;
  while (m--) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }
  SegmentTree seg;
  seg.init(n);
  seg.modify(1, 1, 1);
  for (int i = 1; i <= n; i++)
    for (const auto &[l, r] : segments)
      seg.modify(i + l, i + r, seg.query(i, i));
  cout << seg.query(n, n);
}
