#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long MAXN = 998244353;
const long long INF = INT_MAX;
long long dp[200007];
long long ranges[200007];
vector<long long> valid;
long long n, k;
long long go(long long i) {
  if (i >= n) return 0;
  if (i == n - 1) return 1;
  if (dp[i] != -1) return dp[i];
  dp[i] = 0;
  for (auto x : valid) {
    (dp[i] = (dp[i] % MOD + go(i + x) % MOD) % MOD) %= MOD;
  }
  return dp[i] % MOD;
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < (n + 1); i++) dp[i] = -1;
  for (long long i = 0; i < (k); i++) {
    long long l, r;
    cin >> l >> r;
    ranges[l] += 1;
    ranges[r + 1] -= 1;
  }
  for (long long i = 1; i < (n); i++) ranges[i] += ranges[i - 1];
  for (long long i = 0; i < (n + 1); i++)
    if (ranges[i] > 0) valid.push_back(i);
  cout << go(0);
  for (long long i = 0; i < (n + 1); i++) cerr << dp[i] << ' ';
  cerr << '\n';
  for (auto x : valid) cerr << x << ' ';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}
