#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 200005
#define mod 998244353
ll tree[MAX] = {0};
ll lazy[MAX] = {0};
void updateRangeUtil(ll si, ll ss, ll se, ll us, ll ue, ll diff) {
  if (lazy[si] != 0) {
    tree[si] += (se - ss + 1) * lazy[si];
    tree[si] %= mod;
    if (ss != se) {
      lazy[si * 2 + 1] += lazy[si];
      lazy[si * 2 + 1] %= mod;
      lazy[si * 2 + 2] += lazy[si];
      lazy[si * 2 + 2] %= mod;
    }
    lazy[si] = 0;
  }
  if (ss > se || ss > ue || se < us)
    return;
  if (ss >= us && se <= ue) {
    tree[si] += (se - ss + 1) * diff;
    tree[si] %= mod;
    if (ss != se) {
      lazy[si * 2 + 1] += diff;
      lazy[si * 2 + 1] %= mod;
      lazy[si * 2 + 2] += diff;
      lazy[si * 2 + 2] %= mod;
    }
    return;
  }
  ll mid = (ss + se) / 2;
  updateRangeUtil(si * 2 + 1, ss, mid, us, ue, diff);
  updateRangeUtil(si * 2 + 2, mid + 1, se, us, ue, diff);
  tree[si] = tree[si * 2 + 1] + tree[si * 2 + 2];
  tree[si] %= mod;
}
void updateRange(ll n, ll us, ll ue, ll diff) {
  updateRangeUtil(0, 0, n - 1, us, ue, diff);
}
ll getSumUtil(ll ss, ll se, ll qs, ll qe, ll si) {
  if (lazy[si] != 0) {
    tree[si] += (se - ss + 1) * lazy[si];
    tree[si] %= mod;
    if (ss != se) {
      lazy[si * 2 + 1] += lazy[si];
      lazy[si * 2 + 1] %= mod;
      lazy[si * 2 + 2] += lazy[si];
      lazy[si * 2 + 2] %= mod;
    }
    lazy[si] = 0;
  }
  if (ss > se || ss > qe || se < qs)
    return 0;
  if (ss >= qs && se <= qe)
    return tree[si];
  ll mid = (ss + se) / 2;
  ll mkp = getSumUtil(ss, mid, qs, qe, 2 * si + 1) +
           getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
  mkp %= mod;
  return mkp;
}
ll getSum(ll n, ll qs, ll qe) {
  if (qs < 0 || qe > n - 1 || qs > qe) {
    exit(78);
  }
  return getSumUtil(0, n - 1, qs, qe, 0);
}
void constructSTUtil(ll arr[], ll ss, ll se, ll si) {
  if (ss > se)
    return;
  if (ss == se) {
    tree[si] = arr[ss];
    return;
  }
  ll mid = (ss + se) / 2;
  constructSTUtil(arr, ss, mid, si * 2 + 1);
  constructSTUtil(arr, mid + 1, se, si * 2 + 2);
  tree[si] = tree[si * 2 + 1] + tree[si * 2 + 2];
}
void constructST(ll arr[], ll n) { constructSTUtil(arr, 0, n - 1, 0); }
int main() {
  // freopen("in", "r", stdin);
  ll n, k;
  cin >> n >> k;
  ll arr[n + 10];
  for (int i = 0; i < n + 5; i++)
    arr[i] = 0;
  arr[0] = 1;
  constructST(arr, n);
  vector<pair<ll, ll>> ami(k);
  for (auto &a : ami) {
    cin >> a.first;
    cin >> a.second;
  }
  for (int i = 0; i < n; i++) {
    for (auto a : ami) {
      if (i + a.first >= n)
        continue;
      updateRange(n, i + a.first, min(i + a.second, n - 1), getSum(n, i, i));
    }
  }
  cout << getSum(n, n - 1, n - 1) << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 2000005
#define mod 998244353
ll tree[MAX] = {0};
ll lazy[MAX] = {0};
void updateRangeUtil(ll si, ll ss, ll se, ll us, ll ue, ll diff) {
  if (lazy[si] != 0) {
    tree[si] += (se - ss + 1) * lazy[si];
    tree[si] %= mod;
    if (ss != se) {
      lazy[si * 2 + 1] += lazy[si];
      lazy[si * 2 + 1] %= mod;
      lazy[si * 2 + 2] += lazy[si];
      lazy[si * 2 + 2] %= mod;
    }
    lazy[si] = 0;
  }
  if (ss > se || ss > ue || se < us)
    return;
  if (ss >= us && se <= ue) {
    tree[si] += (se - ss + 1) * diff;
    tree[si] %= mod;
    if (ss != se) {
      lazy[si * 2 + 1] += diff;
      lazy[si * 2 + 1] %= mod;
      lazy[si * 2 + 2] += diff;
      lazy[si * 2 + 2] %= mod;
    }
    return;
  }
  ll mid = (ss + se) / 2;
  updateRangeUtil(si * 2 + 1, ss, mid, us, ue, diff);
  updateRangeUtil(si * 2 + 2, mid + 1, se, us, ue, diff);
  tree[si] = tree[si * 2 + 1] + tree[si * 2 + 2];
  tree[si] %= mod;
}
void updateRange(ll n, ll us, ll ue, ll diff) {
  updateRangeUtil(0, 0, n - 1, us, ue, diff);
}
ll getSumUtil(ll ss, ll se, ll qs, ll qe, ll si) {
  if (lazy[si] != 0) {
    tree[si] += (se - ss + 1) * lazy[si];
    tree[si] %= mod;
    if (ss != se) {
      lazy[si * 2 + 1] += lazy[si];
      lazy[si * 2 + 1] %= mod;
      lazy[si * 2 + 2] += lazy[si];
      lazy[si * 2 + 2] %= mod;
    }
    lazy[si] = 0;
  }
  if (ss > se || ss > qe || se < qs)
    return 0;
  if (ss >= qs && se <= qe)
    return tree[si];
  ll mid = (ss + se) / 2;
  ll mkp = getSumUtil(ss, mid, qs, qe, 2 * si + 1) +
           getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
  mkp %= mod;
  return mkp;
}
ll getSum(ll n, ll qs, ll qe) {
  if (qs < 0 || qe > n - 1 || qs > qe) {
    exit(78);
  }
  return getSumUtil(0, n - 1, qs, qe, 0);
}
void constructSTUtil(ll arr[], ll ss, ll se, ll si) {
  if (ss > se)
    return;
  if (ss == se) {
    tree[si] = arr[ss];
    return;
  }
  ll mid = (ss + se) / 2;
  constructSTUtil(arr, ss, mid, si * 2 + 1);
  constructSTUtil(arr, mid + 1, se, si * 2 + 2);
  tree[si] = tree[si * 2 + 1] + tree[si * 2 + 2];
}
void constructST(ll arr[], ll n) { constructSTUtil(arr, 0, n - 1, 0); }
int main() {
  // freopen("in", "r", stdin);
  ll n, k;
  cin >> n >> k;
  ll arr[n + 10];
  for (int i = 0; i < n + 5; i++)
    arr[i] = 0;
  arr[0] = 1;
  constructST(arr, n);
  vector<pair<ll, ll>> ami(k);
  for (auto &a : ami) {
    cin >> a.first;
    cin >> a.second;
  }
  for (int i = 0; i < n; i++) {
    for (auto a : ami) {
      if (i + a.first >= n)
        continue;
      updateRange(n, i + a.first, min(i + a.second, n - 1), getSum(n, i, i));
    }
  }
  cout << getSum(n, n - 1, n - 1) << endl;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(n + 1, 0);
  vector<ll> L(k), R(k);
  rep(i, k) { cin >> L[i] >> R[i]; }
  dp[1] = 1;
  rep2(now, 1, n + 1) {
    if (dp[now] == 0)
      continue;
    rep(i, k) {
      rep2(j, L[i], R[i] + 1) {
        if (now + j > n)
          break;
        dp[now + j] += dp[now];
        dp[now + j] %= 998244353;
      }
    }
  }
  cout << dp[n] << endl;

  return 0;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
using namespace std;

const ll mod = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(n + 1, 0LL);
  vector<ll> dpsum(n + 1, 0LL);
  vector<ll> L(k), R(k);
  rep(i, k) { cin >> L[i] >> R[i]; }
  dp[1] = 1;
  dpsum[1] = 1;
  rep2(now, 2, n + 1) {
    rep(i, k) {
      ll L1 = now - L[i];
      ll R1 = now - R[i] - 1;
      if (L1 < 0)
        continue;
      R1 = max(R1, 0LL);
      dp[now] += dpsum[L1] - dpsum[R1];
      dp[now] %= mod;
    }
    dpsum[now] = dpsum[now - 1] + dp[now];
  }
  cout << dp[n] << endl;

  return 0;
}


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

const ll MOD = 998244353;

ll n, k;
bool check[200005];
ll dp[200005];

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      check[j] = true;
    }
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n && i - j > 0; j++) {
      if (check[j]) {
        dp[i] = (dp[i] + dp[i - j]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}

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

const ll MOD = 998244353;

ll n, k;
vector<pair<ll, ll>> v;
vector<ll> sum;
ll dp[200005];

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  v.resize(k);
  sum.resize(k);
  for (auto &i : v) {
    cin >> i.first >> i.second;
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - v[j].first > 0) {
        sum[j] += dp[i - v[j].first];
        sum[j] = (sum[j] + MOD) % MOD;
      }
      dp[i] = (dp[i] + sum[j]) % MOD;
      if (i - v[j].second > 0) {
        sum[j] -= dp[i - v[j].second];
        sum[j] = (sum[j] + MOD) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}


#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF long long(int) 1e18 + 1
#define MAX 200001
#define rep(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  vector<pair<int, int>> d(k);
  rep(i, 0, k) {
    int x, y;
    cin >> x >> y;
    d[i].first = x;
    d[i].second = y;
    rep(i, x, y + 1) s.insert(i);
  }
  vector<long long> dp(n + 2, 0);
  for (auto a : s)
    dp[a + 1]++;
  rep(i, 1, n + 1) {
    for (auto a : s) {
      if (i - a >= 0)
        dp[i] += dp[i - a];
      dp[i] %= 998244353;
    }
  }
  cout << dp[n] << endl;
}

#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF long long(int) 1e18 + 1
#define MAX 200001
#define rep(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  vector<pair<int, int>> d(k);
  vector<long long> bsum(k);
  rep(i, 0, k) {
    int x, y;
    cin >> x >> y;
    d[i].first = x;
    d[i].second = y;
    bsum[i] = 0;
    rep(i, x, y + 1) s.insert(i);
  }
  vector<long long> dp(n + 2, 0);
  for (auto a : s)
    dp[a + 1]++;
  rep(i, 1, n + 1) {
    rep(j, 0, k) {
      if (i - d[j].first >= 0)
        bsum[j] += dp[i - d[j].first];
      if (i - d[j].second > 0)
        bsum[j] -= dp[i - d[j].second - 1];
      dp[i] += bsum[j];
      dp[i] %= 998244353;
    }
  }
  cout << dp[n] << endl;
}


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

template <long long mod> class Mod {
  long long value;
  void set_value(const long long x) { this->value = x % mod; }

public:
  Mod() { set_value(0ll); }

  template <typename T> Mod(T x = 0) { set_value((long long)x); }

  friend std::istream &operator>>(std::istream &is, Mod &x) {
    long long tmp;
    is >> tmp;
    x.set_value(tmp);
    return is;
  }

  friend std::ostream &operator<<(std::ostream &os, const Mod &x) {
    os << x.value;
    return os;
  }

  operator long long() const { return this->value; }

  template <typename T> bool operator<(const T x) {
    return this->value < (long long)x;
  }

  template <typename T> bool operator<=(const T x) {
    return this->value <= (long long)x;
  }

  template <typename T> bool operator>(const T x) {
    return this->value > (long long)x;
  }

  template <typename T> bool operator>=(const T x) {
    return this->value >= (long long)x;
  }

  template <typename T> bool operator==(const T x) {
    return this->value == (long long)x;
  }

  template <typename T> Mod &operator=(const T x) {
    set_value((long long)x);
    return *this;
  }

  template <typename T> Mod &operator&=(const T x) {
    set_value(this->value & (long long)x);
    return *this;
  }

  template <typename T> Mod &operator|=(const T x) {
    set_value(this->value | (long long)x);
    return *this;
  }

  template <typename T> Mod &operator^=(const T x) {
    set_value(this->value ^ (long long)x);
    return *this;
  }

  template <typename T> Mod &operator<<=(const T x) {
    set_value(this->value << (long long)x);
    return *this;
  }

  template <typename T> Mod &operator>>=(const T x) {
    set_value(this->value >> (long long)x);
    return *this;
  }

  template <typename T> Mod &operator+=(const T x) {
    set_value(this->value + (long long)x);
    return *this;
  }

  template <typename T> Mod &operator-=(const T x) {
    set_value(this->value - (long long)x + mod);
    return *this;
  }

  template <typename T> Mod &operator*=(const T x) {
    set_value(this->value * (long long)x);
    return *this;
  }

  template <typename T> Mod &operator/=(const T x) {
    long long a = (long long)x;
    long long b = mod;
    long long u = 1;
    long long v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= mod;
    if (u < 0)
      u += mod;
    *this *= Mod(u);
    return *this;
  }

  template <typename T> Mod operator&(const T x) const {
    return Mod(*this) &= x;
  }

  template <typename T> Mod operator|(const T x) const {
    return Mod(*this) |= x;
  }

  template <typename T> Mod operator^(const T x) const {
    return Mod(*this) ^= x;
  }

  template <typename T> Mod operator<<(const T x) const {
    return Mod(*this) <<= x;
  }

  template <typename T> Mod operator>>(const T x) const {
    return Mod(*this) >>= x;
  }

  template <typename T> Mod operator+(const T x) const {
    return Mod(*this) += x;
  }

  template <typename T> Mod operator-(const T x) const {
    return Mod(*this) -= x;
  }

  template <typename T> Mod operator*(const T x) const {
    return Mod(*this) *= x;
  }

  template <typename T> Mod operator/(const T x) const {
    return Mod(*this) /= x;
  }

  Mod &operator++() {
    *this += 1;
    return *this;
  }

  Mod &operator--() {
    this->set_value(--this->value);
    return *this;
  }

  Mod operator++(int) {
    Mod ret(*this);
    ++*this;
    return ret;
  }

  Mod operator--(int) {
    Mod ret(*this);
    --*this;
    return ret;
  }
};

template <long long MOD>
Mod<MOD> f(size_t n, vector<Mod<MOD>> &dp, vector<int> &S) {
  if (dp[n] == 0) {
    for (int s : S) {
      if (n - s < n) {
        dp[n] += f(n - s, dp, S);
      }
    }
  }
  return dp[n];
}

int main() {
  constexpr long long MOD = 998244353;
  size_t N, K;
  cin >> N >> K;

  vector<Mod<MOD>> dp(N, 0);
  dp[0] = 1;

  int L, R;
  vector<int> S;
  for (size_t i = 0; i < K; i++) {
    cin >> L >> R;
    for (int s = L; s <= R; s++) {
      S.push_back(s);
    }
  }
  f(N - 1, dp, S);
  cout << dp.back() << endl;

  // int L, R;
  // vector<pair<int, int>> LR;
  // for (size_t i = 0; i < K; i++)
  // {
  //     cin >> L >> R;
  //     LR.push_back(make_pair(L, R));
  // }
  // for (size_t i = 0; i < K; i++)
  // {
  //     }
}

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

template <long long mod> class Mod {
  long long value;
  void set_value(const long long x) { this->value = x % mod; }

public:
  Mod() { set_value(0ll); }

  template <typename T> Mod(T x = 0) { set_value((long long)x); }

  friend std::istream &operator>>(std::istream &is, Mod &x) {
    long long tmp;
    is >> tmp;
    x.set_value(tmp);
    return is;
  }

  friend std::ostream &operator<<(std::ostream &os, const Mod &x) {
    os << x.value;
    return os;
  }

  operator long long() const { return this->value; }

  template <typename T> bool operator<(const T x) {
    return this->value < (long long)x;
  }

  template <typename T> bool operator<=(const T x) {
    return this->value <= (long long)x;
  }

  template <typename T> bool operator>(const T x) {
    return this->value > (long long)x;
  }

  template <typename T> bool operator>=(const T x) {
    return this->value >= (long long)x;
  }

  template <typename T> bool operator==(const T x) {
    return this->value == (long long)x;
  }

  template <typename T> Mod &operator=(const T x) {
    set_value((long long)x);
    return *this;
  }

  template <typename T> Mod &operator&=(const T x) {
    set_value(this->value & (long long)x);
    return *this;
  }

  template <typename T> Mod &operator|=(const T x) {
    set_value(this->value | (long long)x);
    return *this;
  }

  template <typename T> Mod &operator^=(const T x) {
    set_value(this->value ^ (long long)x);
    return *this;
  }

  template <typename T> Mod &operator<<=(const T x) {
    set_value(this->value << (long long)x);
    return *this;
  }

  template <typename T> Mod &operator>>=(const T x) {
    set_value(this->value >> (long long)x);
    return *this;
  }

  template <typename T> Mod &operator+=(const T x) {
    set_value(this->value + (long long)x);
    return *this;
  }

  template <typename T> Mod &operator-=(const T x) {
    set_value(this->value - (long long)x + mod);
    return *this;
  }

  template <typename T> Mod &operator*=(const T x) {
    set_value(this->value * (long long)x);
    return *this;
  }

  template <typename T> Mod &operator/=(const T x) {
    long long a = (long long)x;
    long long b = mod;
    long long u = 1;
    long long v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= mod;
    if (u < 0)
      u += mod;
    *this *= Mod(u);
    return *this;
  }

  template <typename T> Mod operator&(const T x) const {
    return Mod(*this) &= x;
  }

  template <typename T> Mod operator|(const T x) const {
    return Mod(*this) |= x;
  }

  template <typename T> Mod operator^(const T x) const {
    return Mod(*this) ^= x;
  }

  template <typename T> Mod operator<<(const T x) const {
    return Mod(*this) <<= x;
  }

  template <typename T> Mod operator>>(const T x) const {
    return Mod(*this) >>= x;
  }

  template <typename T> Mod operator+(const T x) const {
    return Mod(*this) += x;
  }

  template <typename T> Mod operator-(const T x) const {
    return Mod(*this) -= x;
  }

  template <typename T> Mod operator*(const T x) const {
    return Mod(*this) *= x;
  }

  template <typename T> Mod operator/(const T x) const {
    return Mod(*this) /= x;
  }

  Mod &operator++() {
    *this += 1;
    return *this;
  }

  Mod &operator--() {
    this->set_value(--this->value);
    return *this;
  }

  Mod operator++(int) {
    Mod ret(*this);
    ++*this;
    return ret;
  }

  Mod operator--(int) {
    Mod ret(*this);
    --*this;
    return ret;
  }
};

int main() {
  constexpr long long MOD = 998244353;
  size_t N, K;
  cin >> N >> K;

  vector<Mod<MOD>> dp(2 * N, 0);
  dp[0] = 0;

  int L, R;
  vector<pair<int, int>> S;
  for (size_t i = 0; i < K; i++) {
    cin >> L >> R;
    dp[L]++;
    dp[R + 1]--;
    S.push_back(make_pair(L, R));
  }

  for (size_t i = 1; i < N; i++) {
    dp[i] += dp[i - 1];
    for (pair<int, int> s : S) {
      int l = s.first;
      int r = s.second;
      dp[i + l] += dp[i];
      dp[i + r + 1] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}


#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long, long long>
#define pld pair<long double, long double>
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
ll mod = 998244353;
ll INF = 1e18;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll fastexp(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result *= x;
    x *= x;
    n = n / 2;
  }
  return result;
}

ll modularExp(ll x, ll n, ll mod) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n = n / 2;
  }
  return (result) % mod;
}
bool isPrime(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
bool mycomp(pll &a, pll &b) {
  if (a.F != b.F)
    return a.F < b.F;
  else
    return a.S < b.S;
}
vector<ll> par(2005), sz(2005, 1);

ll froot(ll x) {
  if (x == par[x])
    return x;
  return par[x] = froot(par[x]);
}
void solve() {
  ll n, k;
  cin >> n >> k;
  vector<pll> v(k);
  vector<ll> dp(n + 1);
  ll i, j;
  for (i = 0; i < k; i++)
    cin >> v[i].F >> v[i].S;
  sort(v.begin(), v.end());
  vector<ll> st;
  for (i = 0; i < k; i++) {
    for (j = v[i].F; j <= v[i].S; j++)
      st.pb(j);
  }

  ll sz = st.size();
  dp[1] = 1;
  for (i = 1; i <= n; i++) {
    ll mdiff = (n - i);
    ll idx = upper_bound(st.begin(), st.end(), mdiff) - st.begin();
    idx--;
    for (j = 0; j <= min(sz - 1, idx); j++)
      dp[i + st[j]] = (dp[i + st[j]] % mod + dp[i] % mod) % mod;
  }
  cout << dp[n];
}

int main() {
  ios;
  ll t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long, long long>
#define pld pair<long double, long double>
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
ll mod = 998244353;
ll INF = 1e18;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll fastexp(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result *= x;
    x *= x;
    n = n / 2;
  }
  return result;
}

ll modularExp(ll x, ll n, ll mod) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n = n / 2;
  }
  return (result) % mod;
}
bool isPrime(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  return true;
}
bool mycomp(pll &a, pll &b) {
  if (a.F != b.F)
    return a.F < b.F;
  else
    return a.S < b.S;
}
vector<ll> par(2005), sz(2005, 1);

ll froot(ll x) {
  if (x == par[x])
    return x;
  return par[x] = froot(par[x]);
}
void solve() {
  ll n, k;
  cin >> n >> k;
  vector<pll> v(k);
  vector<ll> dp(n + 1), pre(n + 1);
  ll i, j;
  for (i = 0; i < k; i++)
    cin >> v[i].F >> v[i].S;
  dp[1] = 1;
  pre[1] = 1;
  for (i = 2; i <= n; i++) {
    for (j = 0; j < k; j++) {
      ll l = max(0LL, i - v[j].F);
      ll r = max(0LL, i - v[j].S - 1);
      // cout<<l<<" "<<r<<"!\\n";
      dp[i] = (dp[i] + pre[l] % mod - pre[r] % mod + mod) % mod;
    }
    pre[i] = (pre[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
}

int main() {
  ios;
  ll t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}


// Library
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define ABS(X) (((X) > 0) ? (X) : -(X))
#define YN(X) ((X) ? "YES" : "NO")
#define SWAP(T, X, Y)                                                          \\
  {                                                                            \\
    T t;                                                                       \\
    t = X;                                                                     \\
    X = Y;                                                                     \\
    Y = t;                                                                     \\
  }

#define F1 first
#define S2 second
#define PB push_back
#define MP make_pair

// Global Tables

// ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>> &v) {
  ull i, j;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < v[i].size(); j++) {
      cout << v[i][j];
      if (j == v[i].size() - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}

void PrintVector(vi &v) {
  ull i;
  for (i = 0; i < v.size(); i++) {
    cout << v[i];
    if (i == v.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

void PrintArr(int *a, ull N) {
  ull i;
  for (i = 0; i < N; i++) {
    cout << a[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

void PreProcessTables() {
  ull i, j;
  for (i = 0; i < SZA; i++) {
    for (j = 0; j < SZB; j++) {
      break;
    }
    break;
  }
}

void TC(int t) {
  ull mod_val = 998244353;
  ull dp[200001] = {0};
  ull N, K, L, R;
  cin >> N >> K;
  vector<pair<ull, ull>> seg;
  for (ull i = 0; i < K; i++) {
    cin >> L >> R;
    seg.push_back(make_pair(L, R));
  }
  dp[1] = 1;
  for (ull i = 2; i < N + 1; i++) {
    for (ull j = 0; j < K; j++) {
      if (i <= seg[j].first) {
        continue;
      } else {
        L = seg[j].first;
        R = min(seg[j].second, i - 1);
        for (ull k = L; k <= R; k++) {
          dp[i] += dp[i - k];
        }
      }
    }
    dp[i] %= mod_val;
  }
  cout << dp[N] << endl;
}

// Main

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  PreProcessTables();

  int T = 1, t;
  // cin >> T;
  for (t = 1; t <= T; t++) {
    TC(t);
  }
  return 0;
}

// Library
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define ABS(X) (((X) > 0) ? (X) : -(X))
#define YN(X) ((X) ? "YES" : "NO")
#define SWAP(T, X, Y)                                                          \\
  {                                                                            \\
    T t;                                                                       \\
    t = X;                                                                     \\
    X = Y;                                                                     \\
    Y = t;                                                                     \\
  }

#define F1 first
#define S2 second
#define PB push_back
#define MP make_pair

// Global Tables

// ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>> &v) {
  ull i, j;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < v[i].size(); j++) {
      cout << v[i][j];
      if (j == v[i].size() - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}

void PrintVector(vi &v) {
  ull i;
  for (i = 0; i < v.size(); i++) {
    cout << v[i];
    if (i == v.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

void PrintArr(int *a, ull N) {
  ull i;
  for (i = 0; i < N; i++) {
    cout << a[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

void PreProcessTables() {
  ull i, j;
  for (i = 0; i < SZA; i++) {
    for (j = 0; j < SZB; j++) {
      break;
    }
    break;
  }
}

void TC(int t) {
  ull mod_val = 998244353;
  ull dp[200001] = {0};
  ull dpsum[200001] = {0};
  ull N, K, L, R;
  cin >> N >> K;
  vector<pair<ull, ull>> seg;
  for (ull i = 0; i < K; i++) {
    cin >> L >> R;
    seg.push_back(make_pair(L, R));
  }
  dp[1] = 1;
  dpsum[1] = 1;
  for (ull i = 2; i < N + 1; i++) {
    for (ull j = 0; j < K; j++) {
      if (i <= seg[j].first) {
        continue;
      } else {
        L = seg[j].first;
        R = min(seg[j].second, i - 1);
        dp[i] = (dp[i] + mod_val + dpsum[i - L] - dpsum[i - R - 1]) % mod_val;
      }
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % mod_val;
  }
  cout << dp[N] << endl;
}

// Main

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  PreProcessTables();

  int T = 1, t;
  // cin >> T;
  for (t = 1; t <= T; t++) {
    TC(t);
  }
  return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>
#define int long long
using namespace std;
const int N = 5e5, M = 15, MOD = 998244353;
int a[N];
int f[N];
int x[M], y[M];
int n, m;
int qzh[N];
inline int modbez(int a, int b) {
  register int res = a % b;
  if (res < 0)
    return res + b;
  else
    return res;
}
void DP() {
  f[n] = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      f[i] = modbez(f[i] + qzh[i + x[j]] - qzh[i + y[j] + 1], MOD);
    }
    qzh[i] = modbez(qzh[i + 1] + f[i], MOD);
  }
  cout << f[1] % MOD << endl;
}
void common_DP() {
  f[n] = 1;
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      for (int k = x[j]; k <= y[j]; k++) {
        if (i + k <= n) {
          f[i] = (f[i] + f[i + k]) % MOD;
        }
      }
  cout << f[1] << endl;
}
signed main() {
  memset(f, 0, sizeof(f));
  memset(a, 0, sizeof(a));
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  if (n > 1e4)
    common_DP();
  else
    DP();
}

#include <cstring>
#include <iostream>
#include <stdio.h>
#define int long long
using namespace std;
const int N = 5e5, M = 15, MOD = 998244353;
int a[N];
int f[N];
int x[M], y[M];
int n, m;
int qzh[N];
inline int modbez(int a, int b) {
  register int res = a % b;
  if (res < 0)
    return res + b;
  else
    return res;
}
void DP() {
  f[n] = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      f[i] = modbez(f[i] + qzh[i + x[j]] - qzh[i + y[j] + 1], MOD);
    }
    qzh[i] = modbez(qzh[i + 1] + f[i], MOD);
  }
  cout << f[1] % MOD << endl;
}
void common_DP() {
  f[n] = 1;
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      for (int k = x[j]; k <= y[j]; k++) {
        if (i + k <= n) {
          f[i] = (f[i] + f[i + k]) % MOD;
        }
      }
  cout << f[1] << endl;
}
signed main() {
  memset(f, 0, sizeof(f));
  memset(a, 0, sizeof(a));
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  if (n < 1e4)
    common_DP();
  else
    DP();
}


#include <iostream>
#include <vector>
using LL = long long;
using namespace std;
int mod = 998244353;
int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> Li(K), Ri(K);
  vector<bool> S_has(N + 1, false);
  for (int i = 0; i < K; i++) {
    cin >> Li[i] >> Ri[i];
    for (int j = Li[i]; j <= Ri[i]; j++) {
      S_has[j] = true;
    }
  }
  vector<LL> Dp(N + 1, 0);
  Dp[1] = 1;

  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= N; j++) {
      if (S_has[j] == true && i + j <= N) {
        Dp[i + j] = (Dp[i + j] + Dp[i]) % mod;
      }
    }
  }
  cout << Dp[N] << endl;

  return 0;
}

#include <iostream>
#include <vector>
using LL = long long;
using namespace std;
int mod = 998244353;
int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> Li(K), Ri(K);
  vector<bool> S_has(N + 1, false);
  for (int i = 0; i < K; i++) {
    cin >> Li[i] >> Ri[i];
    for (int j = Li[i]; j <= Ri[i]; j++) {
      S_has[j] = true;
    }
  }
  vector<LL> Dp(N + 1, 0);
  Dp[1] = 1;

  for (int i = 2; i <= N; i++) {
    Dp[i] += Dp[i - 1];
    for (int k = 0; k < K; k++) {
      if (i - Li[k] > 0) {
        Dp[i] += Dp[i - Li[k]];
      }
      if (i - Ri[k] - 1 > 0) {
        Dp[i] -= Dp[i - Ri[k] - 1];
      }
    }
    while (Dp[i] < 0) {
      Dp[i] += mod;
    }
    Dp[i] = Dp[i] % mod;
  }
  LL ans = Dp[N] - Dp[N - 1];
  while (ans < 0) {
    ans += mod;
  }
  cout << ans << endl;

  return 0;
}