#include <bits/stdc++.h>
using namespace std;

#ifdef _LOCAL
  #include <utils/debug.hpp>
  #include <utils/random_generate.hpp>
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
  #define debug(...) 42
  #define generate_string(...) 42
  #define generate_array(...) 42
  #define generate_unique_array(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void scan(){}
template <class Head, class... Tail>
void scan(Head&& head, Tail&&... tail) {
  cin >> head;
  scan(forward<Tail>(tail)...);
}

void print(){}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
  for (auto v: vs){
    cout << v;
    if (&v != &vs.back()) cout << " ";
  }
  cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

const ll MOD = 998244353;

struct mint {
  ll x;
  mint(ll x = 0): x((x % MOD + MOD) % MOD){}
  mint operator-() const {return mint(-x);}

  mint& operator+=(const mint a){
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }

  mint& operator-=(const mint a){
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }

mint& operator*=(const mint a) {(x *= a.x) %= MOD; return *this;}
mint operator+(const mint a) const {return mint(*this) += a;}
mint operator-(const mint a) const {return mint(*this) -= a;}
mint operator*(const mint a) const {return mint(*this) *= a;}

  mint pow(ll t) const{
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
mint inv() const {return pow(MOD - 2);}
  mint& operator/=(const mint a) {return *this *= a.inv();}
  mint operator/(const mint a) const {return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) {return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}
string to_string(mint a){return to_string(a.x);}
typedef std::vector<mint> vmi;
typedef std::vector<vmi> vmi2;
typedef std::vector<vmi2> vmi3;
typedef std::vector<vmi3> vmi4;

void solve(){
  ll n, k;
  scan(n, k);
  vmi dp(n + 1, 0), cum(n + 2, 0);
  vl ls(k), rs(k);
  rep(i, k) scan(ls[i], rs[i]);
  // x: x - rk ~ x - lk

  dp[0] = 1, cum[1] = 1;
  For(i, 1, n + 1){
    rep(j, k) if (i - ls[j] >= 0)
      dp[i] += cum[i - ls[j] + 1] - cum[max(0LL, i - rs[j])];
    cum[i + 1] = dp[i] + cum[i];
  }

  println(dp[n - 1]);
}

void test(ll num = 0, bool verbose = false){
  rep(i, max(1LL, num)){
    ll t = clock();
    if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
    solve();
    if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  #ifdef _LOCAL
    test(6, true);
  #else
    ll t = 0;
    if (multiple_queries) cin >> t;
    test(t, false);
  #endif
  return 0;
}

Measured memory_bytes: 6352