#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long MOD = 998244353;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const long long N = 3e+5 + 7;
vector<long long> adj[N];
long long vis[N] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
int t = 1;
long long n, k;
long long pre[N];
vector<long long> v;
long long dp[N];
long long func(long long ind) {
  if (ind == n) return 1;
  if (ind >= n + 1) return 0;
  if (dp[ind] != -1) return dp[ind];
  long long ans = 0;
  for (auto it : v) ans += func(ind + it);
  return dp[ind] = ans;
}
void MAIN() {
  cin >> n >> k;
  for (long long i = 0; i <= n + 1; i++) dp[i] = -1;
  for (long long i = 1; i <= k; i++) {
    long long l, r;
    cin >> l >> r;
    pre[l]++;
    pre[r + 1]--;
  }
  for (long long i = 1; i <= n; i++) pre[i] += pre[i - 1];
  for (long long i = 1; i <= n; i++)
    if (pre[i] >= 1) v.push_back(i);
  cout << func(1) % MOD;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  ;
  while (t--) {
    MAIN();
  }
}
