#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int MOD = 998244353;
int n, k;
int dp[N + 2];
vector<int> adj;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  clock_t ck;
  ck = clock();
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      adj.push_back(j);
    }
  }
  sort(adj.begin(), adj.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j : adj) {
      if (j > i) break;
      dp[i] += dp[i - j];
      dp[i] %= MOD;
    }
  }
  cout << dp[n] << '\n';
  ck = clock() - ck;
  cerr << "It took " << 1.0 * ck / CLOCKS_PER_SEC << " sec\n";
  return 0;
}
