#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i, j, mod = 998244353;
  cin >> n >> k;
  vector<pair<long, long>> d(k);
  for (j = 0; j < k; j++) {
    cin >> d[j].first >> d[j].second;
  }
  vector<long long> ans(n + 1 + 100000, 0), cur(n + 1 + 100000, 0);
  long long l, r, res;
  res = 1;
  for (i = 1; i < n; i++) {
    for (j = 0; j < k; j++) {
      l = d[j].first;
      r = d[j].second + 1;
      cur[i + l] += res;
      cur[i + r] -= res;
    }
    ans[i + 1] = (ans[i] + cur[i + 1]) % mod;
    res = (ans[i] + cur[i + 1]) % mod;
  }
  ans[n] %= mod;
  if (ans[n] < 0) {
    ans[n] += mod;
  }
  cout << ans[n] << endl;
  return 0;
}
