#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
const long long MOD = 998244353;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const long long MAXN = 1e+5 + 7;
long long ft[MAXN];
void update(int i, long long v) {
  for (; i <= MAXN; i += i & -i) ft[i] += v, ft[i] %= MOD;
}
long long get(int i) {
  long long ans = 0;
  for (; i > 0; i -= i & -i) ans += ft[i], ans %= MOD;
  return ans;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (auto &a : seg) cin >> a.first >> a.second;
  sort(seg.begin(), seg.end());
  update(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      long long l = seg[j].first, r = seg[j].second;
      if (l > i) break;
      if (i >= l and i > r) {
        update(i, (get(i - l) - get(i - r - 1) + MOD) % MOD);
      } else if (i <= r and r > l)
        update(i,
               (get(i - l) - get(i - min(1ll * (i - 1), r) - 1) + MOD) % MOD);
    }
  }
  cout << (get(n) - get(n - 1) + MOD) % MOD << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
