#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }
#define errOutSeparator(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;
};
std::ostream& operator<<(std::ostream& os, const range_t& r) {
  os << "Range L:" << r.l << " R:" << r.r << ";";
  return os;
}

using reachable_t = struct {
  int64_t r;
  int64_t v;
};
std::ostream& operator<<(std::ostream& os, const reachable_t& r) {
  os << "Reachable R:" << r.r << " V:" << r.v << ";";
  return os;
}

static constexpr int64_t MaxN = 200000;
static constexpr int64_t MaxK = 10;
static constexpr int64_t MOD = 998244353;
static std::vector<range_t> rgs;
static std::array<reachable_t, MaxN> reachables;
static int64_t n;

void addToReachable(int64_t l, int64_t r, int64_t v) {
  r = std::min(r, n - 1);
  if (l > r) {
    return;
  }
  if (reachables[l].v == 0) {
    reachables[l].r = r;
    reachables[l].v = v;
    return;
  }
  if (reachables[l].r == r) {
    reachables[l].v += v;
    reachables[l].v %= MOD;
    return;
  }

  if (reachables[l].r > r) {
    addToReachable(r + 1, reachables[l].r, reachables[l].v);
    reachables[l].r = r;
    reachables[l].v += v;
    return;
  }

  addToReachable(reachables[l].r + 1, r, v);
  reachables[l].v += v;
  reachables[l].v %= MOD;
}

int64_t solve(void) {
  std::sort(rgs.begin(), rgs.end(),
            [](auto const& lhv, auto const& rhv) { return lhv.l < rhv.l; });
  reachables[0].r = 0;
  reachables[0].v = 1;
  for (auto i = 0; i < n - 1; i++) {
    auto const& r = reachables[i];
    if (r.v == 0) {
      continue;
    }
    if (r.r != i) {
      addToReachable(i + 1, r.r, r.v);
    }
    for (auto const& rg : rgs) {
      if (i + rg.l >= n) {
        break;
      }
      addToReachable(i + rg.l, i + rg.r, r.v);
    }
  }
  return reachables[n - 1].v;
}

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;
}
