#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;
using range_t = struct {
  int64_t l;
  int64_t r;
};
static constexpr int64_t MOD = 998244353;
static constexpr int64_t MaxN = 200000;
static std::vector<range_t> rgs;
static std::vector<int64_t> dp;
static int64_t n;

int64_t subSolve(int64_t p) {
  if (dp[p] >= 0) {
    return dp[p];
  }
  int64_t ret = 0;
  for (auto const& rg : rgs) {
    if (p - rg.l < 0) {
      break;
    }
    for (int64_t pp = rg.l; pp <= rg.r; pp++) {
      if (p - pp == 0) {
        ret += 1;
        ret %= MOD;
      }
      if (p - pp < 0) {
        break;
      }
      ret += subSolve(p - pp);
      ret %= MOD;
    }
  }
  dp[p] = ret;
  return ret;
}

int64_t solve(void) {
  dp.resize(n);
  for (auto& d : dp) {
    d = -1;
  }
  std::sort(rgs.begin(), rgs.end(),
            [](auto const& lhv, auto const& rhv) { return lhv.l < rhv.l; });
  return subSolve(n - 1);
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  int64_t k;
  std::cin >> k;
  rgs.resize(k);
  for (int i = 0; i < k; i++) {
    std::cin >> rgs[i].l;
    std::cin >> rgs[i].r;
  }
  auto const res = solve();
  std::cout << res << std::endl;
  return 0;
}
