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