#include <bits/stdc++.h>
using namespace std;
const long long Maxn = (long long)1e5 + 1;
const long double pi = acos(-1);
const long long mod = 998244353;
const long long inf = (long long)1e18;
template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
  for (long long i = 0; i < (long long)A.size(); i++) out << A[i] << " ";
  return out;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long Q = 1;
  while (Q--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> A(n + 1, 0);
    while (k--) {
      long long l, r;
      cin >> l >> r;
      A[l]++;
      if (r < n) A[r + 1]--;
    }
    for (long long i = 1; i < n + 1; i++) A[i] += A[i - 1];
    vector<long long> B;
    for (long long i = 0; i < n; i++)
      if (A[i] != 0) B.push_back(i);
    vector<long long> dp(n + 1, 0);
    dp[1] = 1;
    for (long long i = 1; i < n + 1; i++) {
      for (auto ele : B) {
        if (i >= ele) {
          dp[i] = (dp[i] + dp[i - ele]) % mod;
        }
      }
    }
    cout << dp[n] << endl;
  }
  return 0;
}
