#include <iostream>
#include <tuple>
#include <vector>
#include <cstdint>

template <std::int64_t Modulus>
class ModularInteger {
 public:
  static constexpr std::int64_t kModulus = Modulus;

  constexpr ModularInteger() : value_(0) {}
  constexpr ModularInteger(std::int64_t value) : value_(value % kModulus) {
    value_ += (value_ < 0) * kModulus;
  }
  constexpr std::int64_t GetValue() const {
    return value_;
  }

  constexpr ModularInteger operator+=(ModularInteger other) {
    value_ += other.value_ - (value_ + other.value_ >= kModulus) * kModulus;
    return *this;
  }
  constexpr ModularInteger operator-=(ModularInteger other) {
    value_ += (value_ < other.value_) * kModulus - other.value_;
    return *this;
  }
  constexpr ModularInteger operator*=(ModularInteger other) {
    value_ = value_ * other.value_ % kModulus;
    return *this;
  }
  constexpr ModularInteger operator/=(ModularInteger other) {
    value_ = value_ * other.Inverse().value_ % kModulus;
    return *this;
  }

  constexpr ModularInteger operator+(ModularInteger other) const {
    return ModularInteger(*this) += other;
  }
  constexpr ModularInteger operator-(ModularInteger other) const {
    return ModularInteger(*this) -= other;
  }
  constexpr ModularInteger operator*(ModularInteger other) const {
    return ModularInteger(*this) *= other;
  }
  constexpr ModularInteger operator/(ModularInteger other) const {
    return ModularInteger(*this) /= other;
  }

  constexpr bool operator==(ModularInteger other) const {
    return value_ == other.value_;
  }
  constexpr bool operator!=(ModularInteger other) const {
    return value_ != other.value_;
  }

  constexpr ModularInteger Inverse() const {
    std::int64_t a = kModulus, b = value_, x = 0, y = 1;
    while (b > 0) {
      const auto q = a / b;
      a -= q * b;
      x -= q * y;
      std::swap(a, b);
      std::swap(x, y);
    }
    return x;
  }

  constexpr ModularInteger Power(std::int64_t exponent) const {
    if (exponent < 0) {
      return Inverse().Power(-exponent);
    }
    ModularInteger product = 1;
    auto multiplier = *this;
    while (exponent > 0) {
      if (exponent & 1) {
        product *= multiplier;
      }
      multiplier *= multiplier;
      exponent >>= 1;
    }
    return product;
  }

  friend std::ostream& operator<<(std::ostream& stream, ModularInteger i) {
    return stream << i.value_;
  }
  friend std::istream& operator>>(std::istream& stream, ModularInteger& i) {
    return stream >> i.value_;
  }

 private:
  std::int64_t value_;
};

template <typename T>
class FenwickTree {
 public:
  FenwickTree(std::size_t size) : data_(size) {}

  void Add(std::size_t index, T value) {
    ++index;
    while (index <= data_.size()) {
      data_[index - 1] += value;
      index += index & -index;
    }
  }

  T Sum(std::size_t end) const {
    T sum = 0;
    while (end) {
      sum += data_[end - 1];
      end &= end - 1;
    }
    return sum;
  }

  T Sum(std::size_t begin, std::size_t end) const {
    return Sum(end) - Sum(begin);
  }

 private:
  std::vector<T> data_;
};

int main() {
  constexpr std::int64_t kModulus = 998244353;
  using Integer = ModularInteger<kModulus>;
  int N, K;
  std::cin >> N >> K;
  std::vector<std::tuple<int, int>> intervals(K);
  for (int i = 0; i < K; ++i) {
    int l, r;
    std::cin >> l >> r;
    intervals[i] = {l, r};
  }
  FenwickTree<Integer> fenwick_tree(N);
  fenwick_tree.Add(0, 1);
  for (int i = 0; i < N; ++i) {
    Integer sum = 0;
    for (const auto [l, r] : intervals) {
      sum += fenwick_tree.Sum(std::max(0, i - r), std::max(0, i - l + 1));
    }
    fenwick_tree.Add(i, sum);
  }
  std::cout << fenwick_tree.Sum(N - 1, N) << std::endl;
  return 0;
}


Measured memory_bytes: 4840