#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  const uint64_t mod = 998244353;
  uint64_t n, k;
  cin >> n >> k;
  uint64_t l[10];
  uint64_t r[10];
  for (uint64_t i = 0; i < k; ++i) {
    cin >> l[i] >> r[i];
  }
  uint64_t d[400020] = {0, 1, mod-1};
  uint64_t p = 1;
  for (uint64_t i = 1; i < n; ++i) {
    for (uint64_t j = 0; j < k; ++j) {
      d[i+l[j]] = (d[i+l[j]] + p) % mod;
      d[i+r[j]+1] = (d[i+r[j]+1] + mod - p) % mod;
    }
    p = (p + d[i+1]) % mod;
  }

  cout << p << endl;
}
