#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(2 * n, 0);
  ll wa = 0;
  vector<ll> l(k), r(k);
  for (int i = 0; i < (k); ++i) {
    cin >> l[i] >> r[i];
    ++r[i];
  }
  dp[1] = 1;
  ll mod = 998244353;
  for (int i = 0; i < (n + 1); ++i) {
    wa += dp[i];
    wa = wa % mod;
    for (int j = 0; j < (k); ++j) {
      dp[i + l[j]] += wa;
      dp[i + l[j]] = dp[i + l[j]] % mod;
      dp[i + r[j]] -= wa;
      dp[i + r[j]] = dp[i + r[j]] % mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
