#include <cstdint>
#include <bits/stdc++.h>
#define ll long long
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(){
    ll n,k;
    cin >> n >> k;
    vector<ll> L(k);
    vector<ll> R(k);
    for(ll i=0;i<k;i++){
      cin >> L[i] >> R[i];
    }
    ll minli=INFINITY;
    for(ll i=0;i<k;i++){
      minli = min(L[i],minli);
    }
    vector<modint<998244353>> data(n+1);
    data[1]=1;
    for(ll i=1;i<=n;i++){
      if(data[i].a==0)continue;
      for(ll si=0;si<k;si++){
        for(ll di=L[si];di<=min(R[si],n-i);di++){
          data[i+di]+=data[i];
        }
      }
    }
    cout << data[n].a;
}
