#include <bits/stdc++.h>
using namespace std;
constexpr int64_t kMod = 998244353;
struct Step {
  int64_t from;
  int64_t left;
  int64_t right;
  int64_t pattern;
};
int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<pair<int64_t, int64_t>> ranges;
  ranges.reserve(10);
  for (int64_t k = 0; k < K; ++k) {
    int64_t l, r;
    cin >> l >> r;
    ranges.push_back({l, r});
  }
  vector<Step> steps;
  int64_t step = 1;
  for (int64_t n = 1; n <= N; ++n) {
    set<int64_t> froms;
    if (n != 1) step = 0;
    for (auto it = steps.begin(); it != steps.end();) {
      if (froms.count((*it).from)) {
        ++it;
        continue;
      }
      if ((*it).left <= n && n <= (*it).right) {
        step += (*it).pattern;
        step %= kMod;
        froms.insert((*it).from);
      }
      if ((*it).right == n) {
        it = steps.erase(it);
      } else {
        ++it;
      }
    }
    if (n != N) {
      for (auto& range : ranges) {
        steps.push_back({n, n + range.first, n + range.second, step});
      }
    }
  }
  cout << step << endl;
  return 0;
}
