#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "trapv"
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long mod = 998244353;
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long res = power(a, b / 2);
  if (b & 1)
    return res * res * a;
  else
    return res * res;
}
const long long sz = 200000 + 1;
long long dp[sz];
vector<long long> v;
long long go(long long pos, long long n) {
  if (dp[pos] != -1) {
    return dp[pos];
  } else if (pos == n) {
    return 1;
  } else {
    long long ans = 0;
    for (long long i = 0; i < (long long)v.size(); i++) {
      if (pos + v[i] <= n) ans = (ans % mod + go(pos + v[i], n) % mod) % mod;
    }
    dp[pos] = ans;
    return dp[pos];
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  long long n, k;
  cin >> n >> k;
  long long diff[200000 + 1] = {0};
  for (long long i = 1; i <= k; i++) {
    long long l, r;
    cin >> l >> r;
    diff[l]++;
    diff[r + 1]--;
  }
  for (long long i = 1; i < n + 1; i++) {
    diff[i] = diff[i] + diff[i - 1];
    if (diff[i] != 0) v.push_back(i);
  }
  cout << go(1, n) << '\n';
  return 0;
}
