#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
const int mod = (int)1e9 + 7;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> A(2e5 + 10), arr;
  for (int i = 0; i < k; i++) {
    int e1, e2;
    cin >> e1 >> e2;
    A[e1]++, A[e2 + 1]--;
  }
  for (int i = 1; i < A.size(); i++) A[i] += A[i - 1];
  vector<ll> DP(n);
  for (int i = 0; i < A.size(); i++)
    if (A[i]) arr.emplace_back(i);
  DP[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < arr.size(); j++)
      if (i >= arr[j]) {
        DP[i] += DP[i - arr[j]];
        DP[i] %= 998244353;
      }
  }
  cout << DP[n - 1];
}
int main(int argc, char *argv[]) {
  clock_t clk_start = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int cases = 1;
  for (int i = 1; i <= cases; i++) {
    solve();
  }
  cerr << "Execution Time: " << fixed
       << double(clock() - clk_start) / double(CLOCKS_PER_SEC)
       << setprecision(6) << " sec\n";
}
