// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/19/20 20:59:59
// -----------------------------------

#include <bits/stdc++.h>
#include "../../../library/include/modular.hpp"

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n,k; cin>>n>>k;
  vector<pair<int,int>> LR(k);
  for (int i = 0; i < k; i++) {
    int l,r; cin>>l>>r;
    LR[i] = {l,r+1};
  }
  using mint = Modular<998244353>;
  vector<mint> dp(n, 0);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    auto cv = dp[i];
    for (auto [l,r]:LR) {
      if (i+l < n)
        dp[i+l] += cv;
      if (i+r < n)
        dp[i+r] -= cv;
    }
    if (i > 0)
      dp[i+1] += cv;
  }
  cout << dp[n-1] << endl;

  return 0;
}
