#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

int main() {
  int64_t n, k, MA = 998244353;
  cin >> n >> k;
  int64_t l[k], r[k];
  mp::cpp_int sum[k] = {0}, ans[n + 1] = {0};
  for (int i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  ans[1] = 1;
  if (l[0] == 1)
    sum[0] += 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      ans[i] += sum[j];
      ans[i] %= MA;
    }
    for(int j=0; j<k; j++){
      if (i - l[j] >= 0) {
        sum[j] += ans[i - l[j] + 1];
        sum[j] %= MA;
      }
      if (i - r[j] >= 1) {
        sum[j] -= ans[i - r[j]];
        sum[j] += MA;
        sum[j] %= MA;
      }
    }
  }
cout << ans[n];
  return 0;
}