#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = (1ll << 30) - 1;
const ll INFLL = 1ll << 60;
const int MOD = 998244353;
const long double EPS = 1.0e-14;
const int FACN = 510000;
int gcd(int, int);
int lcm(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);
ll modAdd(ll, ll, ll);
ll modSub(ll, ll, ll);
ll modTms(ll, ll, ll);
ll modInv(ll, ll);
ll modDiv(ll, ll, ll);
ll modPow(ll, ll, ll);
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> lr(k);
  vector<ll> dp(n), dps(n);
  for (int(i) = 0; (i) < (k); (i)++) {
    cin >> lr[i].first >> lr[i].second;
  }
  sort((lr).begin(), (lr).end());
  int lritr = 0;
  bool ins = false;
  dp[0] = 1;
  dps[0] = 1;
  for (int i = 1; i < n; ++i) {
    if (!ins && lritr < k && lr[lritr].first <= i) {
      ins = true;
    } else if (ins && i > lr[lritr].second) {
      ins = false;
      ++lritr;
    }
    for (int(j) = 0; (j) < (lritr); (j)++) {
      dp[i] += modSub(dps[i - lr[j].first],
                      i - lr[j].second - 1 >= 0 ? dps[i - lr[j].second - 1] : 0,
                      MOD);
      dp[i] %= MOD;
    }
    if (ins) {
      dp[i] += modSub(dps[i - lr[lritr].first], 0, MOD);
      dp[i] %= MOD;
    }
    dps[i] = dps[i - 1] + dp[i];
    dps[i] %= MOD;
  }
  dp[n - 1] %= MOD;
  cout << dp[n - 1] << endl;
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll modAdd(ll a, ll b, ll m) { return (a + b) % m; }
ll modSub(ll a, ll b, ll m) { return (a > b) ? (a - b) % m : (a - b) % m + m; }
ll modTms(ll a, ll b, ll m) { return a * b % m; }
ll modInv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
ll modDiv(ll a, ll b, ll m) { return modTms(a, modInv(b, m), m); }
ll modPow(ll a, ll n, ll m) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}
