#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1001001001;
const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while (y > 0) {
      if (y & 1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator+=(const mint a) noexcept {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) noexcept {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/=(const mint a) noexcept { return (*this) *= a.inv(); }
  mint operator+(const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/(const mint a) const noexcept {
    mint res(*this);
    return res /= a;
  }
};
ostream& operator<<(ostream& stream, const mint& n) {
  stream << n.x;
  return stream;
};
struct comb {
  vector<mint> fact, ifact;
  comb(int n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; i--) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept {
    if (k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
using P = pair<ll, ll>;
mint dp[200005];
int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<P> s;
  for (ll i = (0); i < (k); i++) {
    ll l, r;
    cin >> l >> r;
    s.emplace_back(l, r);
  }
  dp[0] = 1;
  for (ll i = (0); i < (n); i++) {
    for (ll j = (0); j < (k); j++) {
      ll l = s[j].first;
      ll r = s[j].second;
      for (ll p = (l); p <= (r); p++) {
        if (i + p > n) break;
        dp[i + p] += dp[i];
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
