#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};


int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> s;
    vector<modint<998244353>> dp(n+1);
    for (int i = 0; i < k; i++) {
        int min, max;
        cin >> min >> max;
        for (int j = min; j < max+1; j++) {
            s.push_back(j);
        }
    }
    sort(s.begin(), s.end());

    dp[1] = 1;
    for (int i = 1; i < n+1; i++) {
        for (size_t j = 0; j < s.size(); j++) {
            int idx = i + s[j];
            if (idx <= n) {
                //cout << i << "->" << idx << endl;
                dp[idx]+=dp[i];
            }
        }
    }

    cout << dp[n].value() << endl;
    return 0;
}