#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double EPS = 1e-10;
template <typename T>
void view(T e) {
  cout << e << endl;
}
template <typename T>
void view(const vector<T>& v) {
  for (const auto& e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <typename T>
void view(const vector<vector<T>>& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll MOD = 1000000007;
const ll inf = 1LL << 60;
struct Mint {
  ll v;
  ll _mod;
  Mint() : v(0), _mod(MOD) {}
  Mint(signed v, ll _mod = MOD) : v(v), _mod(_mod) {}
  Mint(ll t, ll _mod = MOD) : _mod(_mod) {
    v = t % _mod;
    if (v < 0) v += _mod;
  }
  Mint pow(ll k) {
    Mint res(1, _mod), tmp(v, _mod);
    while (k) {
      if (k & 1) res *= tmp;
      tmp *= tmp;
      k >>= 1;
    }
    return res;
  }
  static Mint add_identity(ll mod = MOD) { return Mint(0, mod); }
  static Mint mul_identity(ll mod = MOD) { return Mint(1, mod); }
  Mint inv() { return pow(_mod - 2); }
  Mint& operator+=(Mint a) {
    v += a.v;
    if (v >= _mod) v -= _mod;
    return *this;
  }
  Mint& operator-=(Mint a) {
    v += _mod - a.v;
    if (v >= _mod) v -= _mod;
    return *this;
  }
  Mint& operator*=(Mint a) {
    v = v * a.v % _mod;
    return *this;
  }
  Mint& operator/=(Mint a) { return (*this) *= a.inv(); }
  Mint operator+(Mint a) const { return Mint(v, _mod) += a; };
  Mint operator-(Mint a) const { return Mint(v, _mod) -= a; };
  Mint operator*(Mint a) const { return Mint(v, _mod) *= a; };
  Mint operator/(Mint a) const { return Mint(v, _mod) /= a; };
  Mint operator-() const { return v ? Mint(_mod - v, _mod) : Mint(v, _mod); }
  bool operator==(const Mint a) const { return v == a.v; }
  bool operator!=(const Mint a) const { return v != a.v; }
  bool operator<(const Mint a) const { return v < a.v; }
};
ostream& operator<<(ostream& os, Mint m) { return os << m.v; }
Mint nCk(int n, int k) {
  Mint ret = 1;
  for (int i = n; i > n - k; --i) {
    ret *= i;
  }
  for (int i = 1; i <= k; ++i) {
    ret /= i;
  }
  return ret;
}
using Vmi = vector<Mint>;
using VVmi = vector<Vmi>;
using VVVmi = vector<VVmi>;
vector<ll> memo(2e5 + 10, -1);
set<ll, greater<ll>> s;
ll m = 998244353;
ll rec(ll x) {
  if (memo.at(x) != -1) {
    return memo.at(x);
  }
  ll ret = 0;
  for (auto k : s) {
    if (x - k < 0) continue;
    ret += rec(x - k);
    ret %= m;
  }
  memo.at(x) = ret;
  return ret;
}
int main() {
  ll n, k;
  cin >> n >> k;
  memo[0] = 1;
  for (ll i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j < r + 1; j++) {
      s.insert(j);
    }
  }
  cout << rec(n - 1) % m << endl;
  return 0;
}
