#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const long long MOD = 998244353;
long long bit[200005];
long long n, k;
void upd(long long x, long long val) {
  for (; x <= n; x += x & -x) {
    bit[x] = (bit[x] + val) % MOD;
  }
}
long long get(long long x) {
  long long res = 0;
  for (; x > 0; x -= x & -x) {
    res = (res + bit[x]) % MOD;
  }
  return res;
}
void solve_test() {
  cin >> n >> k;
  upd(1, 1);
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    v.push_back({l, r});
  }
  sort(v.begin(), v.end());
  for (long long i = 2; i <= n; i++) {
    long long lo = 0, hi = 0;
    for (long long j = 0; j < k; j++) {
      lo = max(lo, v[j].first);
      hi = v[j].second;
      if (lo > hi) continue;
      if (lo >= i) break;
      hi = min(i - 1, hi);
      long long res = (MOD + get(i - lo) - get(i - hi - 1)) % MOD;
      upd(i, res);
      lo = hi + 1;
    }
  }
  cout << get(n) - get(n - 1) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tests;
  tests = 1;
  while (tests--) {
    solve_test();
  }
  return 0;
}
