#include <bits/stdc++.h>
using namespace std;
const int BIG_NUM = 1e9;
const long long INF = 1000000000000000000;
const long long MOD = 998244353;
struct SegmentTree {
  int n;
  vector<long long> v;
  SegmentTree(int n0) {
    n = 1;
    while (n < n0) {
      n *= 2;
    }
    v.resize(2 * n - 1);
    v[n] = 1;
    for (int i = n - 2; i >= 0; i--) v[i] = v[i * 2 + 1] + v[i * 2 + 2];
  }
  long long query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) {
      r = n;
    }
    if (r <= a || b <= l) {
      return 0;
    }
    if (a <= l && r <= b) {
      return v[k];
    }
    long long ql = query(a, b, 2 * k + 1, l, (l + r) / 2);
    long long qr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return ql + qr;
  }
  void update(int x, int l, int r) {
    int ma = x - l + 1;
    int mi = max(0, x - r);
    x += n - 1;
    v[x] += query(mi, ma);
    v[x] %= MOD;
    while (x > 0) {
      x = (x - 1) / 2;
      v[x] = (v[2 * x + 1] + v[2 * x + 2]) % MOD;
    }
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > v(k);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }
  sort(v.begin(), v.end());
  SegmentTree st(n);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = v[j].first;
      int r = v[j].second;
      st.update(i, l, r);
    }
  }
  cout << st.query(n, n + 1) << endl;
}
