#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

const ll MAX_N = 200200;

ll dp[MAX_N];
ll N, K;
vll S;

ll sub(ll n) {
  if (dp[n] != -1) {
    return dp[n];
  }
  ll ans = 0;
  for (auto s : S) {
    if (n - s < 0)
      break;
    ans = (ans + sub(n - s)) % MOD;
  }
  dp[n] = ans;
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll i, j, k;

  cin >> N >> K;
  vector<pll> P;
  for (i = 0; i < K; i++) {
    ll l, r;
    cin >> l >> r;
    P.push_back(pll(l, r));
  }
  sort(P.begin(), P.end());
  for (i = 0; i < K; i++) {
    ll l = P[i].first;
    ll r = P[i].second;
    for (j = l; j < r + 1; j++) {
      S.push_back(j);
    }
  }

  for (i = 0; i < N; i++) {
    dp[i] = -1;
  }
  dp[0] = 1;
  ll ans = sub(N - 1);
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll i, j, k;

  ll N, K;
  cin >> N >> K;
  vector<pll> P;
  for (i = 0; i < K; i++) {
    ll l, r;
    cin >> l >> r;
    P.push_back(pll(l, r));
  }
  vll C(N, 0);
  C[0] = 1;
  C[1] = -1;
  ll c = 0;
  for (i = 0; i < N; i++) {
    c = (c + C[i]) % MOD;
    for (j = 0; j < K; j++) {
      ll l = P[j].first;
      ll r = P[j].second;
      if (i + l < N) {
        C[i + l] = (C[i + l] + c) % MOD;
      }
      if (i + r + 1 < N) {
        C[i + r + 1] = (C[i + r + 1] + MOD - c) % MOD;
      }
    }
  }
  cout << c << endl;

  return 0;
}


#include <bits/stdc++.h>
#include <ctime>
#include <iostream>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

template <class T> class SegTree {
private:
  int _n;
  int _d;

  template <class U> class SNode {
  public:
    U _min;
    U _max;
    U _sum;
    U _value;
    U _add;
    U _mul;
    bool _used;
    bool _last;

    SNode() {
      _min = 0;
      _max = 0;
      _sum = 0;
      _value = 0;
      _add = 0;
      _mul = 1;
      _used = false;
      _last = false;
    }

    SNode(const SNode<U> &t) { set(t); }

    void set(const SNode<U> &t) {
      _min = t._min;
      _max = t._max;
      _sum = t._sum;
      _value = t._value;
      _add = t._add;
      _mul = t._mul;
      _used = t._used;
      _last = t._last;
    }

    void set(U v) {
      _min = v;
      _max = v;
      _sum = v;
      _value = v;
      _add = 0;
      _mul = 1;
      _last = true;
      _used = true;
    }

    void set(U v, int d) {
      _min = v;
      _max = v;
      _sum = v * (1 << d);
      _value = v;
      _add = 0;
      _mul = 1;
      _last = true;
      _used = true;
    }
  };

  SNode<T> *nodes;

  int dindex(int d) { return (1 << d); }

  T calcvalue(int index, T v, int num = 1) {
    T ret = v * nodes[index]._mul + nodes[index]._add * num;
    return ret;
  }
  T getnodemin(int index) {
    return calcvalue(index, nodes[index]._mul < 0 ? nodes[index]._max
                                                  : nodes[index]._min);
  }
  T getnodemax(int index) {
    return calcvalue(index, nodes[index]._mul >= 0 ? nodes[index]._max
                                                   : nodes[index]._min);
  }
  T getnodesum(int index, int d) {
    return calcvalue(index, nodes[index]._sum, 1 << (_d - 1 - d));
  }
  T getvalue(int index) { return calcvalue(index, nodes[index]._value); }

  void evalnode(int index, int d) {
    if (index < 1)
      return;
    nodes[index]._used = true;
    if (d == _d - 1) {
      nodes[index]._min = getvalue(index);
      nodes[index]._max = getvalue(index);
      nodes[index]._sum = getvalue(index);
    } else if (nodes[index * 2]._used && nodes[index * 2 + 1]._used) {
      nodes[index]._min = min(getnodemin(2 * index), getnodemin(2 * index + 1));
      nodes[index]._max = max(getnodemax(2 * index), getnodemax(2 * index + 1));
      nodes[index]._sum =
          getnodesum(2 * index, d + 1) + getnodesum(2 * index + 1, d + 1);
    } else if (nodes[index * 2]._used) {
      nodes[index]._min = getnodemin(2 * index);
      nodes[index]._max = getnodemax(2 * index);
      nodes[index]._sum = getnodesum(2 * index, d + 1);
    } else if (nodes[index * 2 + 1]._used) {
      nodes[index]._min = getnodemin(2 * index + 1);
      nodes[index]._max = getnodemax(2 * index + 1);
      nodes[index]._sum = getnodesum(2 * index + 1, d + 1);
    }
  }

  // 対象ノードが範囲に含まれるか　-1:
  // 含まれない、　0:部分的に含まれる、1:完全に含む
  int check(int l, int r, int index, int d) {
    int i = index - (1 << d);
    int k = (1 << (_d - d - 1));
    if (r <= i * k || l >= (i + 1) * k)
      return -1;
    if (l <= i * k && r >= (i + 1) * k)
      return 1;
    return 0;
  }

  T getsub_minmax(int l, int r, int index, int d, T m) {
    if (m >= 0) {
      if (check(l, r, index * 2, d + 1) == -1)
        return getmaxsub(l, r, 2 * index + 1, d + 1);
      if (check(l, r, index * 2 + 1, d + 1) == -1)
        return getmaxsub(l, r, 2 * index, d + 1);
      return max(getmaxsub(l, r, 2 * index, d + 1),
                 getmaxsub(l, r, 2 * index + 1, d + 1));
    } else {
      if (check(l, r, index * 2, d + 1) == -1)
        return getminsub(l, r, 2 * index + 1, d + 1);
      if (check(l, r, index * 2 + 1, d + 1) == -1)
        return getminsub(l, r, 2 * index, d + 1);
      return min(getminsub(l, r, 2 * index, d + 1),
                 getminsub(l, r, 2 * index + 1, d + 1));
    }
  }

  T getminsub(int l, int r, int index, int d) {
    if (d == _d - 1 || nodes[index]._last)
      return getnodemin(index);
    if (check(l, r, index, d) == 1)
      return getnodemin(index);
    T ret = calcvalue(index, getsub_minmax(l, r, index, d, -nodes[index]._mul));
    return ret;
  }

  T getmaxsub(int l, int r, int index, int d) {
    if (d == _d - 1 || nodes[index]._last)
      return getnodemax(index);
    if (check(l, r, index, d) == 1)
      return getnodemax(index);
    T ret = calcvalue(index, getsub_minmax(l, r, index, d, nodes[index]._mul));
    return ret;
  }

  T getsumsub(int l, int r, int index, int d) {
    if (d == _d - 1)
      return getnodesum(index, d);
    int i = index - (1 << d);
    int k = (1 << (_d - d - 1));
    if (nodes[index]._last)
      return calcvalue(index, nodes[index]._value) *
             (min(r, (i + 1) * k) - max(l, i * k));
    if (check(l, r, index, d) == 1)
      return getnodesum(index, d);
    T ret = 0;
    int n1 = min(r, i * k + k / 2) - max(l, i * k);
    int n2 = min(r, i * k + k) - max(l, i * k + k / 2);
    if (n1 > 0)
      ret += calcvalue(index, getsumsub(l, r, 2 * index, d + 1), n1);
    if (n2 > 0)
      ret += calcvalue(index, getsumsub(l, r, 2 * index + 1, d + 1), n2);
    return ret;
  }

  void denpan(int index, int d) {
    nodes[index]._last = false;
    T pre = getvalue(index);
    setRangeSub(0, _n, index * 2, d + 1, pre);
    setRangeSub(0, _n, index * 2 + 1, d + 1, pre);
    nodes[index]._add = 0;
    nodes[index]._mul = 1;
  }

  void calcdenpan(int index, int d) {
    T premul = nodes[index]._mul;
    T preadd = nodes[index]._add;
    if (premul != 1) {
      mulRangeSub(0, _n, index * 2, d + 1, premul);
      mulRangeSub(0, _n, index * 2 + 1, d + 1, premul);
    }
    if (preadd != 0) {
      addRangeSub(0, _n, index * 2, d + 1, preadd);
      addRangeSub(0, _n, index * 2 + 1, d + 1, preadd);
    }
    nodes[index]._mul = 1;
    nodes[index]._add = 0;
  }

  void setRangeSub(int l, int r, int index, int d, T v) {
    if (d == _d - 1 || check(l, r, index, d) == 1) {
      nodes[index].set(v, _d - 1 - d);
      return;
    }
    if (nodes[index]._last)
      denpan(index, d);
    calcdenpan(index, d);
    if (check(l, r, index * 2, d + 1) != -1)
      setRangeSub(l, r, index * 2, d + 1, v);
    if (check(l, r, index * 2 + 1, d + 1) != -1)
      setRangeSub(l, r, index * 2 + 1, d + 1, v);
    evalnode(index, d);
  }

  void addRangeSub(int l, int r, int index, int d, T v) {
    if (d == _d - 1 || check(l, r, index, d) == 1) {
      nodes[index]._add += v;
      return;
    }
    if (nodes[index]._last)
      denpan(index, d);
    if (nodes[index]._mul != 1)
      calcdenpan(index, d);
    if (check(l, r, index * 2, d + 1) != -1)
      addRangeSub(l, r, index * 2, d + 1, v);
    if (check(l, r, index * 2 + 1, d + 1) != -1)
      addRangeSub(l, r, index * 2 + 1, d + 1, v);
    evalnode(index, d);
  }

  void mulRangeSub(int l, int r, int index, int d, T v) {
    if (d == _d - 1 || check(l, r, index, d) == 1) {
      nodes[index]._mul *= v;
      nodes[index]._add *= v;
      return;
    }
    if (nodes[index]._last)
      denpan(index, d);
    if (nodes[index]._add != 0)
      calcdenpan(index, d);
    if (check(l, r, index * 2, d + 1) != -1)
      mulRangeSub(l, r, index * 2, d + 1, v);
    if (check(l, r, index * 2 + 1, d + 1) != -1)
      mulRangeSub(l, r, index * 2 + 1, d + 1, v);
    evalnode(index, d);
  }

  T getSub(int i, int index, int d) {
    if (d == _d - 1 || nodes[index]._last || !nodes[index]._used)
      return getvalue(index);
    if (check(i, i + 1, index * 2, d + 1) != -1)
      return calcvalue(index, getSub(i, 2 * index, d + 1));
    return calcvalue(index, getSub(i, 2 * index + 1, d + 1));
  }

public:
  SegTree(int n) {
    _n = n;
    _d = 1;
    int bit = 1;
    while (bit < _n) {
      bit *= 2;
      _d++;
    }
    nodes = new SNode<T>[bit * 2];
    for (int i = 0; i < n; i++)
      nodes[bit + i]._used = true;
    for (int i = bit - 1; i >= 0; i--)
      nodes[i]._used = (nodes[i * 2]._used || nodes[i * 2 + 1]._used);
  }

  ~SegTree() { delete nodes; }

  void set(int i, T value) { setRangeSub(i, i + 1, 1, 0, value); }

  T get(int i) { return getSub(i, 1, 0); }

  // l <= i < r
  void setRange(int l, int r, T value) { setRangeSub(l, r, 1, 0, value); }

  void addRange(int l, int r, T value) { addRangeSub(l, r, 1, 0, value); }

  void mulRange(int l, int r, T value) { mulRangeSub(l, r, 1, 0, value); }

  T getmin(int l, int r) { return getminsub(l, r, 1, 0); }

  T getmax(int l, int r) { return getmaxsub(l, r, 1, 0); }

  T getsum(int l, int r) { return getsumsub(l, r, 1, 0); }
};

struct ModInt {
  static int _BM;
  long long int m_value;

  int getint() const { return (int)m_value; }
  void _mod() {
    if (m_value < 0)
      m_value += ((-m_value) / _BM + 1) * _BM;
    m_value %= _BM;
  }
  ModInt() { m_value = 0; }
  ModInt(int v) {
    m_value = (_LL)v;
    _mod();
  }
  ModInt(_LL v) {
    m_value = (_LL)v;
    _mod();
  }
  ModInt(const ModInt &t) { m_value = t.getint(); }
  ModInt &operator+=(int v) {
    m_value += v;
    _mod();
    return *this;
  }
  ModInt &operator-=(int v) {
    m_value -= v;
    _mod();
    return *this;
  }
  ModInt &operator*=(int v) {
    m_value *= v;
    _mod();
    return *this;
  }
  ModInt &operator+=(_LL v) { return (*this) += (int)(v % _BM); }
  ModInt &operator-=(_LL v) { return (*this) -= (int)(v % _BM); }
  ModInt &operator*=(_LL v) { return (*this) *= (int)(v % _BM); }
  ModInt &operator+=(const ModInt &t) {
    (*this) += t.getint();
    return (*this);
  }
  ModInt &operator*=(const ModInt &t) {
    (*this) *= t.getint();
    return (*this);
  }
  ModInt &operator-=(const ModInt &t) {
    (*this) -= t.getint();
    return (*this);
  }
  bool operator<(const ModInt &v) const { return m_value < v.m_value; }
  bool operator>(const ModInt &v) const { return m_value > v.m_value; }
  bool operator<=(const ModInt &v) const { return m_value <= v.m_value; }
  bool operator>=(const ModInt &v) const { return m_value >= v.m_value; }
  bool operator==(const ModInt &v) const { return m_value == v.m_value; }
  bool operator!=(const ModInt &v) const { return m_value != v.m_value; }
  bool operator<(int v) const { return m_value < v; }
  bool operator>(int v) const { return m_value > v; }
  bool operator<=(int v) const { return m_value <= v; }
  bool operator>=(int v) const { return m_value >= v; }
  bool operator==(int v) const { return m_value == v; }
  bool operator!=(int v) const { return m_value != v; }
  static int reciprocal(_LL a) {
    _LL b = _BM, u = 1, v = 0;
    while (b) {
      _LL t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= _BM;
    if (u < 0)
      u += _BM;
    return (int)u;
  }
  static int reciprocal(int a) { return reciprocal((_LL)a); }

  ModInt &operator/=(const ModInt &t) {
    (*this) /= t.getint();
    return (*this);
  }
  ModInt &operator/=(int v) {
    (*this) *= reciprocal(v);
    return *this;
  }
  ModInt &operator/=(_LL v) {
    (*this) *= reciprocal(v);
    return *this;
  }
  const ModInt operator+(const ModInt &t) const {
    ModInt ans(*this);
    return ans += t;
  }
  const ModInt operator+(int t) const {
    ModInt ans(*this);
    return ans += t;
  }
  const ModInt operator+(_LL t) const {
    ModInt ans(*this);
    return ans += t;
  }
  const ModInt operator-(const ModInt &t) const {
    ModInt ans(*this);
    return ans -= t;
  }
  const ModInt operator-(int t) const {
    ModInt ans(*this);
    return ans -= t;
  }
  const ModInt operator-(_LL t) const {
    ModInt ans(*this);
    return ans -= t;
  }
  const ModInt operator*(const ModInt &t) const {
    ModInt ans(*this);
    return ans *= t;
  }
  const ModInt operator*(int t) const {
    ModInt ans(*this);
    return ans *= t;
  }
  const ModInt operator*(_LL t) const {
    ModInt ans(*this);
    return ans *= t;
  }
  const ModInt operator/(const ModInt &t) const {
    ModInt ans(*this);
    return ans /= t;
  }
  const ModInt operator/(int t) const {
    ModInt ans(*this);
    return ans /= t;
  }
  const ModInt operator/(_LL t) const {
    ModInt ans(*this);
    return ans /= t;
  }

  bool operator==(int t) { return getint() == t; }

  static int modadd(int a, int b) {
    ModInt t(a);
    t += b;
    return t.getint();
  }
  static int modminus(int a, int b) {
    ModInt t(a);
    t -= b;
    return t.getint();
  }
  static int modmul(int a, int b) {
    ModInt t(a);
    t *= b;
    return t.getint();
  }
  static int modadd(_LL a, _LL b) {
    ModInt t(a);
    t += b;
    return t.getint();
  }
  static int modminus(_LL a, _LL b) {
    ModInt t(a);
    t -= b;
    return t.getint();
  }
  static int modmul(_LL a, _LL b) {
    ModInt t(a);
    t *= b;
    return t.getint();
  }
  static int modpow(int a, int b) { return modpow((_LL)a, (_LL)b); }
  static int modpow(_LL a, _LL b) {
    ModInt ans(1);
    int heap[64];
    heap[0] = (a % _BM);
    for (int bit = 0; b >= (((_LL)1) << bit); bit++) {
      if (bit > 0)
        heap[bit] = modmul(heap[bit - 1], heap[bit - 1]);
      if (b & (((_LL)1) << bit)) {
        ans *= heap[bit];
      }
    }
    return ans.getint();
  }

  static int getCombination(_LL n, _LL r) {
    _LL ans;
    ans = 1;
    for (_LL i = 0; i < r; i++)
      ans = modmul(ans, n - i);
    _LL inv = 1;
    for (_LL i = 0; i < r; i++)
      inv = modmul(inv, i + 1);
    return modmul(ans, (_LL)reciprocal(inv));
  }

  static int combination(int n, int r) {
    int *fac = (int *)malloc(sizeof(int) * (n + 1));
    int *facinv = (int *)malloc(sizeof(int) * (n + 1));
    fac[0] = 1;
    for (int k = 1; k <= n; k++)
      fac[k] = modmul(k, fac[k - 1]);
    facinv[n] = reciprocal(fac[n]);
    for (int k = n; k > 0; k--)
      facinv[k - 1] = modmul(k, facinv[k]);

    ModInt ans(fac[n]);
    ans *= facinv[r];
    ans *= facinv[n - r];

    free(fac);
    free(facinv);
    return ans.getint();
  }
};

int ModInt::_BM = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  SegTree<ModInt> st(n);
  st.set(0, ModInt(1));

  vector<pair<int, int>> list(k);
  rep(i, k) cin >> list[i].first >> list[i].second;

  for (int i = 0; i < n; i++) {
    ModInt v = st.get(i);
    rep(j, k) {
      if (i + list[j].first >= n)
        continue;
      st.addRange(i + list[j].first, min(n, i + list[j].second + 1), v);
    }
  }

  cout << st.get(n - 1).getint() << endl;
  return 0;
}

#include <bits/stdc++.h>
#include <ctime>
#include <iostream>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

struct ModInt {
  static int _BM;
  long long int m_value;

  int getint() const { return (int)m_value; }
  void _mod() {
    if (m_value < 0)
      m_value += ((-m_value) / _BM + 1) * _BM;
    m_value %= _BM;
  }
  ModInt() { m_value = 0; }
  ModInt(int v) {
    m_value = (_LL)v;
    _mod();
  }
  ModInt(_LL v) {
    m_value = (_LL)v;
    _mod();
  }
  ModInt(const ModInt &t) { m_value = t.getint(); }
  ModInt &operator+=(int v) {
    m_value += v;
    _mod();
    return *this;
  }
  ModInt &operator-=(int v) {
    m_value -= v;
    _mod();
    return *this;
  }
  ModInt &operator*=(int v) {
    m_value *= v;
    _mod();
    return *this;
  }
  ModInt &operator+=(_LL v) { return (*this) += (int)(v % _BM); }
  ModInt &operator-=(_LL v) { return (*this) -= (int)(v % _BM); }
  ModInt &operator*=(_LL v) { return (*this) *= (int)(v % _BM); }
  ModInt &operator+=(const ModInt &t) {
    (*this) += t.getint();
    return (*this);
  }
  ModInt &operator*=(const ModInt &t) {
    (*this) *= t.getint();
    return (*this);
  }
  ModInt &operator-=(const ModInt &t) {
    (*this) -= t.getint();
    return (*this);
  }
  bool operator<(const ModInt &v) const { return m_value < v.m_value; }
  bool operator>(const ModInt &v) const { return m_value > v.m_value; }
  bool operator<=(const ModInt &v) const { return m_value <= v.m_value; }
  bool operator>=(const ModInt &v) const { return m_value >= v.m_value; }
  bool operator==(const ModInt &v) const { return m_value == v.m_value; }
  bool operator!=(const ModInt &v) const { return m_value != v.m_value; }
  bool operator<(int v) const { return m_value < v; }
  bool operator>(int v) const { return m_value > v; }
  bool operator<=(int v) const { return m_value <= v; }
  bool operator>=(int v) const { return m_value >= v; }
  bool operator==(int v) const { return m_value == v; }
  bool operator!=(int v) const { return m_value != v; }
  static int reciprocal(_LL a) {
    _LL b = _BM, u = 1, v = 0;
    while (b) {
      _LL t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= _BM;
    if (u < 0)
      u += _BM;
    return (int)u;
  }
  static int reciprocal(int a) { return reciprocal((_LL)a); }

  ModInt &operator/=(const ModInt &t) {
    (*this) /= t.getint();
    return (*this);
  }
  ModInt &operator/=(int v) {
    (*this) *= reciprocal(v);
    return *this;
  }
  ModInt &operator/=(_LL v) {
    (*this) *= reciprocal(v);
    return *this;
  }
  const ModInt operator+(const ModInt &t) const {
    ModInt ans(*this);
    return ans += t;
  }
  const ModInt operator+(int t) const {
    ModInt ans(*this);
    return ans += t;
  }
  const ModInt operator+(_LL t) const {
    ModInt ans(*this);
    return ans += t;
  }
  const ModInt operator-(const ModInt &t) const {
    ModInt ans(*this);
    return ans -= t;
  }
  const ModInt operator-(int t) const {
    ModInt ans(*this);
    return ans -= t;
  }
  const ModInt operator-(_LL t) const {
    ModInt ans(*this);
    return ans -= t;
  }
  const ModInt operator*(const ModInt &t) const {
    ModInt ans(*this);
    return ans *= t;
  }
  const ModInt operator*(int t) const {
    ModInt ans(*this);
    return ans *= t;
  }
  const ModInt operator*(_LL t) const {
    ModInt ans(*this);
    return ans *= t;
  }
  const ModInt operator/(const ModInt &t) const {
    ModInt ans(*this);
    return ans /= t;
  }
  const ModInt operator/(int t) const {
    ModInt ans(*this);
    return ans /= t;
  }
  const ModInt operator/(_LL t) const {
    ModInt ans(*this);
    return ans /= t;
  }

  bool operator==(int t) { return getint() == t; }

  static int modadd(int a, int b) {
    ModInt t(a);
    t += b;
    return t.getint();
  }
  static int modminus(int a, int b) {
    ModInt t(a);
    t -= b;
    return t.getint();
  }
  static int modmul(int a, int b) {
    ModInt t(a);
    t *= b;
    return t.getint();
  }
  static int modadd(_LL a, _LL b) {
    ModInt t(a);
    t += b;
    return t.getint();
  }
  static int modminus(_LL a, _LL b) {
    ModInt t(a);
    t -= b;
    return t.getint();
  }
  static int modmul(_LL a, _LL b) {
    ModInt t(a);
    t *= b;
    return t.getint();
  }
  static int modpow(int a, int b) { return modpow((_LL)a, (_LL)b); }
  static int modpow(_LL a, _LL b) {
    ModInt ans(1);
    int heap[64];
    heap[0] = (a % _BM);
    for (int bit = 0; b >= (((_LL)1) << bit); bit++) {
      if (bit > 0)
        heap[bit] = modmul(heap[bit - 1], heap[bit - 1]);
      if (b & (((_LL)1) << bit)) {
        ans *= heap[bit];
      }
    }
    return ans.getint();
  }

  static int getCombination(_LL n, _LL r) {
    _LL ans;
    ans = 1;
    for (_LL i = 0; i < r; i++)
      ans = modmul(ans, n - i);
    _LL inv = 1;
    for (_LL i = 0; i < r; i++)
      inv = modmul(inv, i + 1);
    return modmul(ans, (_LL)reciprocal(inv));
  }

  static int combination(int n, int r) {
    int *fac = (int *)malloc(sizeof(int) * (n + 1));
    int *facinv = (int *)malloc(sizeof(int) * (n + 1));
    fac[0] = 1;
    for (int k = 1; k <= n; k++)
      fac[k] = modmul(k, fac[k - 1]);
    facinv[n] = reciprocal(fac[n]);
    for (int k = n; k > 0; k--)
      facinv[k - 1] = modmul(k, facinv[k]);

    ModInt ans(fac[n]);
    ans *= facinv[r];
    ans *= facinv[n - r];

    free(fac);
    free(facinv);
    return ans.getint();
  }
};

int ModInt::_BM = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ModInt> dp(n);
  vector<pair<int, int>> list(k);
  rep(i, k) cin >> list[i].first >> list[i].second;
  sort(list.begin(), list.end());
  ModInt sum = 0;
  rep(i, n) {
    if (i == 0) {
      dp[0] = 1;
    } else {
      dp[i] = sum;
    }
    rep(j, k) {
      if (list[j].first > i + 1)
        break;
      int addindex = i + 1 - list[j].first;
      int removeindex = i - list[j].second;
      sum += dp[addindex];
      if (removeindex >= 0)
        sum -= dp[removeindex];
    }
  }
  cout << dp[n - 1].getint() << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

const ll MOD = 998244353;

int main() {

  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> imos(k);
  rep(i, k) {
    int L, R;
    cin >> L >> R;
    imos[i] = make_pair(L, R + 1);
  }
  vector<ll> dp(500000, 0);
  dp[1] = 1;
  dp[2] = -1;
  rep(i, 500000) {
    if (i > 0)
      dp[i] += dp[i - 1];
    dp[i] %= MOD;
    rep(j, k) {
      int L = imos[j].first;
      int R = imos[j].second;
      dp[i + L] += dp[i];
      dp[i + L] %= MOD;
      dp[i + R] -= dp[i];
      dp[i + R] = (dp[i + R] + MOD) % MOD;
    }
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

const ll MOD = 998244353;

int main() {

  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> imos(k);
  rep(i, k) {
    int L, R;
    cin >> L >> R;
    imos[i] = make_pair(L, R + 1);
  }
  vector<ll> dp(500000, 0);
  dp[1] = 1;
  dp[2] = -1;
  rep(i, 300000) {
    if (i > 0)
      dp[i] += dp[i - 1];
    dp[i] %= MOD;
    rep(j, k) {
      int L = imos[j].first;
      int R = imos[j].second;
      dp[i + L] += dp[i];
      dp[i + L] %= MOD;
      dp[i + R] -= dp[i];
      dp[i + R] = (dp[i + R] + MOD) % MOD;
    }
  }
  cout << dp[n] << endl;
}


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

// #define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
#define all(v) (v).begin(), (v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
// typedef vector<vector<ll>> mat;
typedef vector<int> vec;

// 繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

struct modint {
  ll n;
  modint() : n(0) { ; }
  modint(ll m) : n(m) {
    if (n >= mod)
      n %= mod;
    else if (n < 0)
      n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
  a.n += b.n;
  if (a.n >= mod)
    a.n -= mod;
  return a;
}
modint operator-=(modint &a, modint b) {
  a.n -= b.n;
  if (a.n < 0)
    a.n += mod;
  return a;
}
modint operator*=(modint &a, modint b) {
  a.n = ((ll)a.n * b.n) % mod;
  return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
  if (n == 0)
    return modint(1);
  modint res = (a * a) ^ (n / 2);
  if (n % 2)
    res = res * a;
  return res;
}

// 逆元(Eucledean algorithm)
ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); }
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
  fact[0] = modint(1);
  for (int i = 0; i < max_n - 1; i++) {
    fact[i + 1] = fact[i] * modint(i + 1);
  }
  factinv[max_n - 1] = modint(1) / fact[max_n - 1];
  for (int i = max_n - 2; i >= 0; i--) {
    factinv[i] = factinv[i + 1] * modint(i + 1);
  }
}
modint comb(int a, int b) {
  if (a < 0 || b < 0 || a < b)
    return 0;
  return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int n, k;
modint dp[100020];

void solve() {
  cin >> n >> k;
  vec s;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    Rep1(j, l, r) { s.push_back(j); }
  }
  int cnt = s.size();
  dp[1] = 1;
  rep1(i, n) {
    rep(j, cnt) { dp[i + s[j]] += dp[i]; }
  }
  cout << dp[n] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout << fixed << setprecision(10);
  // init_f();
  // init();
  // int t; cin >> t; rep(i, t)solve();
  solve();
  //   stop
  return 0;
}

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

// #define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
#define all(v) (v).begin(), (v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
// typedef vector<vector<ll>> mat;
typedef vector<int> vec;

// 繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

struct modint {
  ll n;
  modint() : n(0) { ; }
  modint(ll m) : n(m) {
    if (n >= mod)
      n %= mod;
    else if (n < 0)
      n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
  a.n += b.n;
  if (a.n >= mod)
    a.n -= mod;
  return a;
}
modint operator-=(modint &a, modint b) {
  a.n -= b.n;
  if (a.n < 0)
    a.n += mod;
  return a;
}
modint operator*=(modint &a, modint b) {
  a.n = ((ll)a.n * b.n) % mod;
  return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
  if (n == 0)
    return modint(1);
  modint res = (a * a) ^ (n / 2);
  if (n % 2)
    res = res * a;
  return res;
}

// 逆元(Eucledean algorithm)
ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); }
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
  fact[0] = modint(1);
  for (int i = 0; i < max_n - 1; i++) {
    fact[i + 1] = fact[i] * modint(i + 1);
  }
  factinv[max_n - 1] = modint(1) / fact[max_n - 1];
  for (int i = max_n - 2; i >= 0; i--) {
    factinv[i] = factinv[i + 1] * modint(i + 1);
  }
}
modint comb(int a, int b) {
  if (a < 0 || b < 0 || a < b)
    return 0;
  return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int n, k;
modint dp[200020];

void solve() {
  cin >> n >> k;
  vec s, t;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    s.push_back(l);
    t.push_back(r);
    // Rep1(j, l, r){
    //     s.push_back(j);
    // }
  }
  int cnt = s.size();
  dp[1] = 1;
  dp[2] = -1;
  rep1(i, n) {
    dp[i] += dp[i - 1];
    rep(j, k) {
      dp[i + s[j]] += dp[i];
      dp[i + t[j] + 1] -= dp[i];
    }
    // rep(j, cnt){
    //     dp[i+s[j]] += dp[i];
    // }
  }
  modint res = 0;
  // rep1(i, n) dp[i+1] += dp[i];
  // rep1(i, n) res += dp[i];
  cout << dp[n] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout << fixed << setprecision(10);
  // init_f();
  // init();
  // int t; cin >> t; rep(i, t)solve();
  solve();
  //   stop
  return 0;
}


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()

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

const int mod = 998244353;

using ll = long long;
using int64 = long long;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

template <typename T = int64> vector<T> make_v(size_t a) {
  return vector<T>(a);
}

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

template <typename F> struct FixPoint : F {
  FixPoint(F &&f) : F(forward<F>(f)) {}

  template <typename... Args> decltype(auto) operator()(Args &&...args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template <typename F> inline decltype(auto) MFP(F &&f) {
  return FixPoint<F>{forward<F>(f)};
}

template <int mod, int primitiveroot> struct NumberTheoreticTransform {
  vector<vector<int>> rts, rrts;

  void ensure_base(int N) {
    if (rts.size() >= N)
      return;
    rts.resize(N), rrts.resize(N);
    for (int i = 1; i < N; i <<= 1) {
      if (rts[i].size())
        continue;
      int w = mod_pow(primitiveroot, (mod - 1) / (i * 2));
      int rw = inverse(w);
      rts[i].resize(i), rrts[i].resize(i);
      rts[i][0] = 1, rrts[i][0] = 1;
      for (int k = 1; k < i; k++) {
        rts[i][k] = mul(rts[i][k - 1], w);
        rrts[i][k] = mul(rrts[i][k - 1], rw);
      }
    }
  }

  inline int mod_pow(int x, int n) {
    int ret = 1;
    while (n > 0) {
      if (n & 1)
        ret = mul(ret, x);
      x = mul(x, x);
      n >>= 1;
    }
    return ret;
  }

  inline int inverse(int x) { return mod_pow(x, mod - 2); }

  inline unsigned add(unsigned x, unsigned y) {
    x += y;
    if (x >= mod)
      x -= mod;
    return x;
  }

  inline unsigned mul(unsigned a, unsigned b) { return 1ull * a * b % mod; }

  void ntt(vector<int> &a, bool rev) {
    const int N = (int)a.size();
    ensure_base(N);
    for (int i = 0, j = 1; j + 1 < N; j++) {
      for (int k = N >> 1; k > (i ^= k); k >>= 1)
        ;
      if (i > j)
        swap(a[i], a[j]);
    }
    for (int i = 1; i < N; i <<= 1) {
      for (int j = 0; j < N; j += i * 2) {
        for (int k = 0; k < i; k++) {
          int s = a[j + k], t = mul(a[j + k + i], rev ? rrts[i][k] : rts[i][k]);
          a[j + k] = add(s, t), a[j + k + i] = add(s, mod - t);
        }
      }
    }
    if (rev) {
      int temp = inverse(N);
      for (int i = 0; i < N; i++)
        a[i] = mul(a[i], temp);
    }
  }

  vector<int> multiply(vector<int> a, vector<int> b) {
    int need = a.size() + b.size() - 1;
    int sz = 1;
    while (sz < need)
      sz <<= 1;
    a.resize(sz, 0);
    b.resize(sz, 0);
    ntt(a, false);
    ntt(b, false);
    for (int i = 0; i < sz; i++)
      a[i] = mul(a[i], b[i]);
    ntt(a, true);
    return a;
  }
};

template <typename T> struct FormalPowerSeries : vector<T> {
  using vector<T>::vector;
  using P = FormalPowerSeries;

  using MULT = function<P(P, P)>;

  static MULT &get_mult() {
    static MULT mult = nullptr;
    return mult;
  }

  static void set_fft(MULT f) { get_mult() = f; }

  FormalPowerSeries(const vector<T> &v)
      : FormalPowerSeries(v.begin(), v.end()) {}

  P operator+(const P &r) const { return P(*this) += r; }

  P operator-(const P &r) const { return P(*this) -= r; }

  P operator*(const P &r) const { return P(*this) *= r; }

  P operator*(const T &v) const { return P(*this) *= v; }

  P operator/(const P &r) const { return P(*this) /= r; }

  P &operator+=(const P &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < r.size(); i++)
      (*this)[i] += r[i];
    return *this;
  }

  P &operator-=(const P &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < r.size(); i++)
      (*this)[i] -= r[i];
    return *this;
  }

  P &operator*=(const T &v) {
    const int n = (int)this->size();
    for (int k = 0; k < n; k++)
      (*this)[k] *= v;
    return *this;
  }

  P &operator*=(const P &r) {
    if (this->empty() || r.empty()) {
      this->clear();
      return *this;
    }
    assert(get_mult() != nullptr);
    auto ret = get_mult()(*this, r);
    this->resize(ret.size());
    for (int k = 0; k < ret.size(); k++)
      (*this)[k] = ret[k];
    return *this;
  }

  P operator-() const {
    P ret(this->size());
    for (int i = 0; i < this->size(); i++)
      ret[i] = -(*this)[i];
    return ret;
  }

  P &operator/=(const P &r) { return *this *= r.inv(); }

  P pre(int sz) const {
    return P(begin(*this), begin(*this) + min((int)this->size(), sz));
  }

  P rev() const {
    P ret(*this);
    reverse(begin(ret), end(ret));
    return ret;
  }

  P diff() const {
    const int n = (int)this->size();
    P ret(max(0, n - 1));
    for (int i = 1; i < n; i++)
      ret[i - 1] = (*this)[i] * T(i);
    return ret;
  }

  P integral() const {
    const int n = (int)this->size();
    P ret(n + 1);
    ret[0] = T(0);
    for (int i = 0; i < n; i++)
      ret[i + 1] = (*this)[i] / T(i + 1);
    return ret;
  }

  // F(0) must not be 0 ,1/fを(deg-1)次まで
  P inv(int deg = -1) const {
    assert(((*this)[0]) != T(0));
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    P ret({T(1) / (*this)[0]});
    for (int i = 1; i < deg; i <<= 1) {
      ret = (ret * T(2) - ret * ret * pre(i << 1)).pre(i << 1);
    }
    return ret.pre(deg);
  }

  // F(0) must be 1
  P log(int deg = -1) const {
    assert((*this)[0] == 1);
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    return (this->diff() * this->inv(deg)).integral().pre(deg);
  }

  // F(0) must be 1
  P sqrt(int deg = -1) const {
    assert((*this)[0] == T(1));
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    P ret({T(1)});
    T inv2 = T(1) / T(2);
    for (int i = 1; i < deg; i <<= 1) {
      ret = (ret + pre(i << 1) * ret.inv(i << 1)) * inv2;
    }
    return ret.pre(deg);
  }

  // F(0) must be 0
  P exp(int deg = -1) const {
    assert((*this)[0] == T(0));
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    P ret({T(1)}), g({T(1)});
    for (int i = 1; i < deg; i <<= 1) {
      ret = (ret * (pre(i << 1) + g - ret.log(i << 1))).pre(i << 1);
    }
    return ret.pre(deg);
  }

  // べき乗(k乗,deg次まで）
  P pow(int64_t k, int deg = -1) const {
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    for (int i = 0; i < n; i++) {
      if ((*this)[i] != T(0)) {
        T rev = T(1) / (*this)[i];
        P C(*this * rev);
        P D(n - i);
        for (int j = i; j < n; j++)
          D[j - i] = C[j];
        D = (D.log() * k).exp() * (*this)[i].pow(k);
        P E(deg);
        if (i * k > deg)
          return E;
        auto S = i * k;
        for (int j = 0; j + S < deg && j < D.size(); j++)
          E[j + S] = D[j];
        return E;
      }
    }
    return *this;
  }

  T eval(T x) const {
    T r = 0, w = 1;
    for (auto &v : *this) {
      r += w * v;
      w *= x;
    }
    return r;
  }
};

template <int mod, int rev_lim = 1000000> struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    static int uku[rev_lim + 1] = {};
    if (x <= rev_lim && uku[x])
      return uku[x];
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    if (x <= rev_lim)
      uku[x] = u;
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt<mod>;

int main() {
  NumberTheoreticTransform<mod, 3> ntt;

  using FPS = FormalPowerSeries<mint>;
  auto mult = [&](const FPS::P &a, const FPS::P &b) {
    int as = a.size(), bs = b.size();
    vector<int> x(as), y(bs);
    for (int i = 0; i < as; i++)
      x[i] = a[i].x;
    for (int i = 0; i < bs; i++)
      y[i] = b[i].x;
    auto ret = ntt.multiply(x, y);
    vector<mint> z(begin(ret), end(ret));
    return z;
  };
  FPS::set_fft(mult);

  int N, K;
  cin >> N >> K;
  FormalPowerSeries<mint> C(N), D(N);
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      C[j] = 1;
    }
  }
  D[0] = 1;
  cout << (C / (D - C))[N - 1] << endl;

  return 0;
}

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()

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

const int mod = 998244353;

using ll = long long;
using int64 = long long;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

template <typename T = int64> vector<T> make_v(size_t a) {
  return vector<T>(a);
}

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

template <typename F> struct FixPoint : F {
  FixPoint(F &&f) : F(forward<F>(f)) {}

  template <typename... Args> decltype(auto) operator()(Args &&...args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template <typename F> inline decltype(auto) MFP(F &&f) {
  return FixPoint<F>{forward<F>(f)};
}

template <int mod, int primitiveroot> struct NumberTheoreticTransform {
  vector<vector<int>> rts, rrts;

  void ensure_base(int N) {
    int rtss = rts.size();
    if (rtss >= N)
      return;
    rts.resize(N), rrts.resize(N);
    for (int i = 1; i < N; i <<= 1) {
      if (rts[i].size())
        continue;
      int w = mod_pow(primitiveroot, (mod - 1) / (i * 2));
      int rw = inverse(w);
      rts[i].resize(i), rrts[i].resize(i);
      rts[i][0] = 1, rrts[i][0] = 1;
      for (int k = 1; k < i; k++) {
        rts[i][k] = mul(rts[i][k - 1], w);
        rrts[i][k] = mul(rrts[i][k - 1], rw);
      }
    }
  }

  inline int mod_pow(int x, int n) {
    int ret = 1;
    while (n > 0) {
      if (n & 1)
        ret = mul(ret, x);
      x = mul(x, x);
      n >>= 1;
    }
    return ret;
  }

  inline int inverse(int x) { return mod_pow(x, mod - 2); }

  inline unsigned add(unsigned x, unsigned y) {
    x += y;
    if (x >= mod)
      x -= mod;
    return x;
  }

  inline unsigned mul(unsigned a, unsigned b) { return 1ull * a * b % mod; }

  void ntt(vector<int> &a, bool rev) {
    const int N = (int)a.size();
    ensure_base(N);
    for (int i = 0, j = 1; j + 1 < N; j++) {
      for (int k = N >> 1; k > (i ^= k); k >>= 1)
        ;
      if (i > j)
        swap(a[i], a[j]);
    }
    for (int i = 1; i < N; i <<= 1) {
      for (int j = 0; j < N; j += i * 2) {
        for (int k = 0; k < i; k++) {
          int s = a[j + k], t = mul(a[j + k + i], rev ? rrts[i][k] : rts[i][k]);
          a[j + k] = add(s, t), a[j + k + i] = add(s, mod - t);
        }
      }
    }
    if (rev) {
      int temp = inverse(N);
      for (int i = 0; i < N; i++)
        a[i] = mul(a[i], temp);
    }
  }

  vector<int> multiply(vector<int> a, vector<int> b) {
    int need = a.size() + b.size() - 1;
    int sz = 1;
    while (sz < need)
      sz <<= 1;
    a.resize(sz, 0);
    b.resize(sz, 0);
    ntt(a, false);
    ntt(b, false);
    for (int i = 0; i < sz; i++)
      a[i] = mul(a[i], b[i]);
    ntt(a, true);
    return a;
  }
};

template <typename T> struct FormalPowerSeries : vector<T> {
  using vector<T>::vector;
  using P = FormalPowerSeries;

  using MULT = function<P(P, P)>;

  static MULT &get_mult() {
    static MULT mult = nullptr;
    return mult;
  }

  static void set_fft(MULT f) { get_mult() = f; }

  FormalPowerSeries(const vector<T> &v)
      : FormalPowerSeries(v.begin(), v.end()) {}

  P operator+(const P &r) const { return P(*this) += r; }

  P operator-(const P &r) const { return P(*this) -= r; }

  P operator*(const P &r) const { return P(*this) *= r; }

  P operator*(const T &v) const { return P(*this) *= v; }

  P operator/(const P &r) const { return P(*this) /= r; }

  P &operator+=(const P &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < r.size(); i++)
      (*this)[i] += r[i];
    return *this;
  }

  P &operator-=(const P &r) {
    int rs = r.size();
    if (rs > this->size())
      this->resize(rs);
    for (int i = 0; i < r.size(); i++)
      (*this)[i] -= r[i];
    return *this;
  }

  P &operator*=(const T &v) {
    const int n = (int)this->size();
    for (int k = 0; k < n; k++)
      (*this)[k] *= v;
    return *this;
  }

  P &operator*=(const P &r) {
    if (this->empty() || r.empty()) {
      this->clear();
      return *this;
    }
    assert(get_mult() != nullptr);
    auto ret = get_mult()(*this, r);
    this->resize(ret.size());
    for (int k = 0; k < ret.size(); k++)
      (*this)[k] = ret[k];
    return *this;
  }

  P operator-() const {
    P ret(this->size());
    for (int i = 0; i < this->size(); i++)
      ret[i] = -(*this)[i];
    return ret;
  }

  P &operator/=(const P &r) { return *this *= r.inv(); }

  P pre(int sz) const {
    return P(begin(*this), begin(*this) + min((int)this->size(), sz));
  }

  P rev() const {
    P ret(*this);
    reverse(begin(ret), end(ret));
    return ret;
  }

  P diff() const {
    const int n = (int)this->size();
    P ret(max(0, n - 1));
    for (int i = 1; i < n; i++)
      ret[i - 1] = (*this)[i] * T(i);
    return ret;
  }

  P integral() const {
    const int n = (int)this->size();
    P ret(n + 1);
    ret[0] = T(0);
    for (int i = 0; i < n; i++)
      ret[i + 1] = (*this)[i] / T(i + 1);
    return ret;
  }

  // F(0) must not be 0 ,1/fを(deg-1)次まで
  P inv(int deg = -1) const {
    assert(((*this)[0]) != T(0));
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    P ret({T(1) / (*this)[0]});
    for (int i = 1; i < deg; i <<= 1) {
      ret = (ret * T(2) - ret * ret * pre(i << 1)).pre(i << 1);
    }
    return ret.pre(deg);
  }

  // F(0) must be 1
  P log(int deg = -1) const {
    assert((*this)[0] == 1);
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    return (this->diff() * this->inv(deg)).integral().pre(deg);
  }

  // F(0) must be 1
  P sqrt(int deg = -1) const {
    assert((*this)[0] == T(1));
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    P ret({T(1)});
    T inv2 = T(1) / T(2);
    for (int i = 1; i < deg; i <<= 1) {
      ret = (ret + pre(i << 1) * ret.inv(i << 1)) * inv2;
    }
    return ret.pre(deg);
  }

  // F(0) must be 0
  P exp(int deg = -1) const {
    assert((*this)[0] == T(0));
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    P ret({T(1)}), g({T(1)});
    for (int i = 1; i < deg; i <<= 1) {
      ret = (ret * (pre(i << 1) + g - ret.log(i << 1))).pre(i << 1);
    }
    return ret.pre(deg);
  }

  // べき乗(k乗,deg次まで）
  P pow(int64_t k, int deg = -1) const {
    const int n = (int)this->size();
    if (deg == -1)
      deg = n;
    for (int i = 0; i < n; i++) {
      if ((*this)[i] != T(0)) {
        T rev = T(1) / (*this)[i];
        P C(*this * rev);
        P D(n - i);
        for (int j = i; j < n; j++)
          D[j - i] = C[j];
        D = (D.log() * k).exp() * (*this)[i].pow(k);
        P E(deg);
        if (i * k > deg)
          return E;
        auto S = i * k;
        for (int j = 0; j + S < deg && j < D.size(); j++)
          E[j + S] = D[j];
        return E;
      }
    }
    return *this;
  }

  T eval(T x) const {
    T r = 0, w = 1;
    for (auto &v : *this) {
      r += w * v;
      w *= x;
    }
    return r;
  }
};

template <int mod, int rev_lim = 1000000> struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    static int uku[rev_lim + 1] = {};
    if (x <= rev_lim && uku[x])
      return uku[x];
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    if (x <= rev_lim)
      uku[x] = u;
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt<mod>;

int main() {
  NumberTheoreticTransform<mod, 3> ntt;

  using FPS = FormalPowerSeries<mint>;
  auto mult = [&](const FPS::P &a, const FPS::P &b) {
    int as = a.size(), bs = b.size();
    vector<int> x(as), y(bs);
    for (int i = 0; i < as; i++)
      x[i] = a[i].x;
    for (int i = 0; i < bs; i++)
      y[i] = b[i].x;
    auto ret = ntt.multiply(x, y);
    vector<mint> z(begin(ret), end(ret));
    return z;
  };
  FPS::set_fft(mult);

  int N, K;
  cin >> N >> K;
  FormalPowerSeries<mint> C(N + 1), D(N + 1);
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      C[j] = 1;
    }
  }
  D[0] = 1;
  cout << (C / (D - C))[N - 1] << endl;

  return 0;
}


#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 998244353;
const int inf = 1 << 30;
const ll lnf = 1ll << 60;

struct mint {
  ll x; // typedef long long ll;
  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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

mint dp[10];

int main() {
  itn n, k;
  cin >> n >> k;
  dp[0] = 1;
  dp[1] = -1;
  vector<int> l(k);
  vector<int> r(k);
  rep(i, k) cin >> l[i] >> r[i];
  rep(i, n) {
    if (i > 0)
      dp[i] += dp[i - 1];
    rep(j, k) {
      mint x = dp[i];
      if (i + l[j] < n)
        dp[i + l[j]] += x;
      if (i + r[j] + 1 < n)
        dp[i + r[j] + 1] -= x;
    }
  }
  cout << dp[n - 1] << endl;
}

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 998244353;
const int inf = 1 << 30;
const ll lnf = 1ll << 60;

struct mint {
  ll x; // typedef long long ll;
  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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

mint dp[1000010];

int main() {
  itn n, k;
  cin >> n >> k;
  dp[0] = 1;
  dp[1] = -1;
  vector<int> l(k);
  vector<int> r(k);
  rep(i, k) cin >> l[i] >> r[i];
  rep(i, n) {
    if (i > 0)
      dp[i] += dp[i - 1];
    rep(j, k) {
      mint x = dp[i];
      if (i + l[j] < n)
        dp[i + l[j]] += x;
      if (i + r[j] + 1 < n)
        dp[i + r[j] + 1] -= x;
    }
  }
  cout << dp[n - 1] << endl;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, n) for (int i = 0; i < n; i++)
#define sz(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
template <typename tp> void read(tp &x) { cin >> x; }
template <typename tp, typename... Args> void read(tp &x, Args &...args) {
  read(x);
  read(args...);
}
const int mxN = (int)1e5, INF = (int)1e9, MOD = 998244353;

bool comp(pair<int, int> &a, pair<int, int> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
void scan(int &number) {
  bool negative = false;
  register int c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar())
    number = number * 10 + c - 48;
  if (negative)
    number *= -1;
}
void solve() {
  int n, k;
  scan(n);
  scan(k);
  pair<int, int> segm[k];
  FOR(i, k) {
    scan(segm[i].first);
    scan(segm[i].second);
  }
  sort(segm, segm + k, comp);
  vector<pair<int, int>> S;
  for (int i = 0; i < k; i++) {
    if (S.empty()) {
      S.push_back(segm[i]);
      continue;
    }
    pair<int, int> a = S.back(), b = segm[i];
    if (a.first == b.first)
      S.back() = b;
    else if (b.first <= a.second)
      S.back().second = b.second;
    else
      S.push_back(b);
  }
  int dp[n + 1];
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    FOR(j, sz(S)) {
      for (int l = S[j].first; l <= S[j].second; l++) {
        if (i - l <= 0)
          break;
        dp[i] = (dp[i] + dp[i - l]) % MOD;
      }
    }
  }
  cout << dp[n];
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, n) for (int i = 0; i < n; i++)
#define sz(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
template <typename tp> void read(tp &x) { cin >> x; }
template <typename tp, typename... Args> void read(tp &x, Args &...args) {
  read(x);
  read(args...);
}
const int mxN = (int)1e5, INF = (int)1e9, MOD = 998244353;

ll rnge(ll l, ll r, vector<ll> &sum) { return sum[r] - sum[l - 1]; }
bool comp(pair<ll, ll> &a, pair<ll, ll> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
void solve() {
  ll n, k;
  read(n, k);
  vector<pair<ll, ll>> segm(k);
  FOR(i, k) read(segm[i].first, segm[i].second);
  sort(all(segm), comp);
  vector<pair<ll, ll>> S;
  for (int i = 0; i < k; i++) {
    if (S.empty()) {
      S.push_back(segm[i]);
      continue;
    }
    pair<int, int> a = S.back(), b = segm[i];
    if (a.first == b.first)
      S.back() = b;
    else if (b.first <= a.second)
      S.back().second = b.second;
    else
      S.push_back(b);
  }
  vector<ll> dp(n + 1), sum(n + 1);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    FOR(j, sz(S)) {
      if (i - S[j].first < 1LL)
        break;
      ll temp;
      if (i - S[j].second > 0)
        temp = (sum[i - S[j].first] - sum[i - S[j].second - 1] + MOD) % MOD;
      else
        temp = sum[i - S[j].first];
      dp[i] = (dp[i] % MOD + temp % MOD) % MOD;
    }
    sum[i] = (dp[i] % MOD + sum[i - 1] % MOD) % MOD;
  }
  cout << dp[n] << '\\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test = 1;
  // read(test);
  while (test--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

const int mod = 998244353;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};

struct mint {
  using ull = unsigned long long int;
  ull v;
  mint(ll vv = 0) { s(vv % mod + mod); }
  mint &s(ull vv) {
    v = vv < mod ? vv : vv - mod;
    return *this;
  }
  // オーバーロード
  mint operator-() const { return mint() - *this; } // 符号反転
  mint &operator+=(const mint &val) { return s(v + val.v); }
  mint &operator-=(const mint &val) { return s(v + mod - val.v); }
  mint &operator*=(const mint &val) {
    v = ull(v) * val.v % mod;
    return *this;
  }
  mint &operator/=(const mint &val) { return *this *= val.inv(); }
  mint operator+(const mint &val) { return mint(*this) += val; }
  mint operator-(const mint &val) { return mint(*this) -= val; }
  mint operator*(const mint &val) { return mint(*this) *= val; }
  mint operator/(const mint &val) { return mint(*this) /= val; }
  mint pow(int n) const {
    mint res(1), x(*this);
    while (n) {
      if (n & 1)
        res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  mint inv() const { return pow(mod - 2); }
  // 拡張ユークリッドの互除法
  /* mint inv()const{
      int x,y;
      int g=extgcd(v,mod,x,y);
      assert(g==1);
      if(x<0)x+=mod;
      return mint(x);
  }*/
  friend ostream &operator<<(ostream &os, const mint &val) {
    return os << val.v;
  } // 出力
  bool operator<(const mint &val) const { return v < val.v; }
  bool operator==(const mint &val) const { return v == val.v; }
  bool operator>(const mint &val) const { return v > val.v; }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  ll N, K;
  cin >> N >> K;
  vector<ll> L(K), R(K);
  rep(i, K) cin >> L[i] >> R[i];
  vector<ll> set;
  rep(i, K) {
    for (int num = L[i]; num <= R[i]; num++) {
      set.pb(num);
    }
  }

  sort(set.begin(), set.end());

  // for(int i = 0; i < set.size(); i++) cout << set[i] << " ";
  // cout << endl;

  vector<mint> dp(N + 5, 0);
  dp[0] = 1;
  for (ll i = 1; i < N; i++) {
    for (ll step : set) {
      // cout << step << endl;
      if (i - step >= 0)
        dp[i] += dp[i - step];
      else
        break;
    }
  }
  // for(int i = 0; i < N; i++) cout << dp[i] << " ";
  // cout << endl;
  cout << dp[N - 1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

const int mod = 998244353;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};

struct mint {
  using ull = unsigned long long int;
  ull v;
  mint(ll vv = 0) { s(vv % mod + mod); }
  mint &s(ull vv) {
    v = vv < mod ? vv : vv - mod;
    return *this;
  }
  // オーバーロード
  mint operator-() const { return mint() - *this; } // 符号反転
  mint &operator+=(const mint &val) { return s(v + val.v); }
  mint &operator-=(const mint &val) { return s(v + mod - val.v); }
  mint &operator*=(const mint &val) {
    v = ull(v) * val.v % mod;
    return *this;
  }
  mint &operator/=(const mint &val) { return *this *= val.inv(); }
  mint operator+(const mint &val) { return mint(*this) += val; }
  mint operator-(const mint &val) { return mint(*this) -= val; }
  mint operator*(const mint &val) { return mint(*this) *= val; }
  mint operator/(const mint &val) { return mint(*this) /= val; }
  mint pow(int n) const {
    mint res(1), x(*this);
    while (n) {
      if (n & 1)
        res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  mint inv() const { return pow(mod - 2); }
  // 拡張ユークリッドの互除法
  /* mint inv()const{
      int x,y;
      int g=extgcd(v,mod,x,y);
      assert(g==1);
      if(x<0)x+=mod;
      return mint(x);
  }*/
  friend ostream &operator<<(ostream &os, const mint &val) {
    return os << val.v;
  } // 出力
  bool operator<(const mint &val) const { return v < val.v; }
  bool operator==(const mint &val) const { return v == val.v; }
  bool operator>(const mint &val) const { return v > val.v; }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  // input
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  rep(i, K) cin >> L[i] >> R[i];
  // dp
  vector<mint> dp(N + 5, 0), dpsum(N + 5, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 1; i < N; i++) {
    for (int k = 0; k < K; k++) {
      int left = i + 1 - R[k];
      int right = i + 1 - L[k];
      if (right < 0)
        continue;
      left = max(left, 1);
      dp[i + 1] += dpsum[right] - dpsum[left - 1];
    }
    dpsum[i + 1] = dpsum[i] + dp[i + 1];
  }
  // output
  cout << dp[N] << endl;
}


#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <climits>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define forn(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define ford(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define int long long
#define ii pair<int, int>
#define ar array
#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ms(x, a) memset(x, (int)(a), sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\\n'
#define ff first
#define ss second
// const int INF = 1e18 ;
// const int MOD = 1e9 + 7 ;
vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = 998244353;
int add(int a, int b) {
  a += b;
  while (a >= MOD)
    a -= MOD;
  return a;
}
void radd(int &a, int b) { a = add(a, b); }
int mult(int a, int b) { return (a * 1LL * b) % MOD; }
void rmult(int &a, int b) { a = mult(a, b); }
int modpow(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1)
      r = mult(r, a);
    a = mult(a, a);
    b >>= 1;
  }
  return r;
}
int choose(int a, int b) {
  if (a < 0 || b < 0)
    return 0;
  if (a < b)
    return 0;
  if (b == 0)
    return 1;
  if (a == b)
    return 1;
  return mult(fact[a], mult(ifact[b], ifact[a - b]));
}
int inverse(int a) { return modpow(a, MOD - 2); }
void init(int _n) {
  fact.clear();
  ifact.clear();
  inv.clear();
  pow2.clear();
  fact.resize(_n + 1);
  ifact.resize(_n + 1);
  inv.resize(_n + 1);
  pow2.resize(_n + 1);
  pow2[0] = 1;
  ifact[0] = 1;
  fact[0] = 1;
  for (int i = 1; i <= _n; i++) {
    pow2[i] = add(pow2[i - 1], pow2[i - 1]);
    fact[i] = mult(fact[i - 1], i);
    // ifact[i]=mult(ifact[i-1],inv[i]);
  }
  ifact[_n] = inverse(fact[_n]);
  for (int i = _n - 1; i >= 1; i--) {
    ifact[i] = mult(ifact[i + 1], i + 1);
  }
  for (int i = 1; i <= _n; i++) {
    inv[i] = mult(fact[i - 1], ifact[i]);
  }
}

const int N = 2e5 + 7;
int n, k;
int m;
vector<int> a;
int dp[N];

int dfs(int idx) {
  if (idx == n - 1)
    return 1;
  int &ans = dp[idx];
  if (ans + 1)
    return ans;
  ans = 0;
  for (auto it : a) {
    if (idx + it < n) {
      radd(ans, dfs(idx + it));
    }
  }
  return ans;
}

void solve() {
  cin >> n >> k;
  forn(i, k) {
    int x, y;
    cin >> x >> y;
    rep(j, x, y + 1) a.push_back(j);
  }
  sort(all(a));
  a.erase(unique(all(a)), a.end());
  ms(dp, -1);
  cout << dfs(0);
}

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

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <climits>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define forn(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define ford(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define int long long
#define ii pair<int, int>
#define ar array
#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ms(x, a) memset(x, (int)(a), sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\\n'
#define ff first
#define ss second

const int N = 2e5 + 7;
const int MOD = 998244353;
int n, k;
int m;
vector<ii> a;
class Fenwick {
public:
  vector<int> ft;
  void init(int n) { ft.resize(n + 1); }
  int g(int x) { return x & (-x); }
  void get(int &x, int y) { // change it
    x += y;
    x += MOD;
    x %= MOD;
  }
  int sum(int pos) {
    int ans = 0;
    for (; pos; pos -= g(pos))
      get(ans, ft[pos]);
    return ans;
  }
  int sum(int l, int r) { return sum(r) - (l == 0 ? 0 : sum(l - 1)); }
  void upd(int pos, int val) {
    for (; pos < ft.size(); pos += g(pos)) {
      get(ft[pos], val);
    }
  }
};

void solve() {
  cin >> n >> k;
  a.resize(k);
  forn(i, k) { cin >> a[i].ff >> a[i].ss; }
  sort(all(a));
  Fenwick ft;
  ft.init(4 * N);
  ft.upd(1, 1);
  ft.upd(2, -1);
  for (int i = 1; i < n; i++) {
    int here = ft.sum(i);
    for (auto [x, y] : a) {
      int l = i + x;
      int r = i + y;
      int left = min(l, r);
      int right = max(l, r) + 1;
      ft.upd(left, here);
      ft.upd(right, -here);
    }
  }
  cout << ft.sum(1, n) % MOD << endl;
}

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


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

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main(void) {
  int N, K;
  cin >> N >> K;

  vector<int> l(K, 0);
  vector<int> r(K, 0);

  for (int i = 0; i < K; ++i) {
    cin >> l[i] >> r[i];
  }

  vector<mint> c(N, 0);

  c[0] = 1;

  for (int i = 1; i < N; ++i) {
    for (int p = 0; p < K; ++p) {
      for (int j = l[p]; j <= r[p]; ++j) {
        if (i - j >= 0)
          c[i] += c[i - j];
      }
    }
  }

  cout << c[N - 1] << endl;

  return 0;
}

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

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main(void) {
  int N, K;
  cin >> N >> K;

  vector<int> l(K, 0);
  vector<int> r(K, 0);

  for (int i = 0; i < K; ++i) {
    cin >> l[i] >> r[i];
  }

  vector<mint> c(N + 1, 0);

  c[0] = 0;
  c[1] = 1;

  for (int i = 2; i <= N; ++i) {
    c[i] = c[i - 1];
    for (int p = 0; p < K; ++p) {
      int rt = max(0, i - r[p] - 1);
      int lt = max(0, i - l[p]);

      c[i] += c[lt] - c[rt];
    }
  }
  mint ans = c[N] - c[N - 1];

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i <= n; ++i)
#define REPR(i, k, n) for (int i = k; i >= n; --i)
#define vin(v, N)                                                              \\
  vi v;                                                                        \\
  rep(i, N) {                                                                  \\
    int x;                                                                     \\
    cin >> x;                                                                  \\
    v.push_back(x);                                                            \\
  }

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

const int MAX_N = 2e5 + 5;

long dp[MAX_N];
void solve() {
  memset(dp, 0, sizeof(dp));
  int N, K;
  cin >> N >> K;
  vi v;
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    REP(j, l, r) { v.push_back(j); }
  }
  dp[0] = 1;
  REP(i, 1, N - 1) {
    for (auto move : v) {
      if (i - move >= 0) {
        dp[i] = (dp[i] + dp[i - move]) % 998244353;
      }
    }
  }
  cout << dp[N - 1];
}

// #define LOCAL 1

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();

  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i <= n; ++i)
#define REPR(i, k, n) for (int i = k; i >= n; --i)
#define vin(v, N)                                                              \\
  vi v;                                                                        \\
  rep(i, N) {                                                                  \\
    int x;                                                                     \\
    cin >> x;                                                                  \\
    v.push_back(x);                                                            \\
  }
#define vout(v, N)                                                             \\
  rep(i, N) { cout << v[i] << " "; }                                           \\
  cout << endl;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

const int MAX_N = 2e5 + 5;

ll dp[MAX_N];
ll pre[MAX_N];
void solve() {
  ll mod = 998244353;
  memset(dp, 0, sizeof(dp));
  memset(pre, 0, sizeof(pre));
  int N, K;
  cin >> N >> K;
  vii v;
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[0] = 1;
  pre[1] = dp[0];
  REP(i, 1, N - 1) {
    rep(j, K) {
      dp[i] = (dp[i] + pre[max(0, i - v[j].first + 1)] -
               pre[max(0, i - v[j].second)] + mod) %
              mod;
    }
    pre[i + 1] = (pre[i] + dp[i]) % mod;
  }
  //    vout(dp, N)
  //    vout(pre, N+1)
  cout << dp[N - 1];
}

// #define LOCAL 1

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      a.push_back(j);
    }
  }
  vector<int> ans(n, 0);
  sort(a.begin(), a.end());
  ans[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int x : a) {
      if (x <= i)
        ans[i] = (ans[i] + ans[i - x]) % 998244353;
      else
        break;
    }
  }
  cout << ans[n - 1] << endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  vector<int> l(k);
  vector<int> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<long long> ans(n, 0);
  ans[0] = 1;
  bool f = false;
  for (int i = 0; i < k; i++) {
    if (l[i] == 1)
      f = true;
  }
  if (f)
    ans[1] = 1;
  else
    ans[1] = 0;
  for (int i = 2; i < n; i++) {
    ans[i] = ans[i - 1];
    for (int j = 0; j < k; j++) {
      if (l[j] <= i)
        ans[i] = ans[i] + ans[i - l[j]];
      if (r[j] + 1 <= i)
        ans[i] = ans[i] + (998244353 - ans[i - r[j] - 1]);
      ans[i] = ans[i] % 998244353;
    }
  }
  cout << ans[n - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>
#define name "test"
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define wrln cout << '\\n';
#define ii pair<int, int>
#define li pair<long long, int>
#define iii pair<int, ii>

using namespace std;
const int N = 2e5 + 100;
const int H = 998244353;

ll n, res, dem, d, sum, k;
ll f[N];

vector<int> v;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen(name ".inp", "r")) {
    freopen(name ".inp", "r", stdin);
    freopen(name ".out", "w", stdout);
  }
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.pb(j);
    }
  }

  sort(v.begin(), v.end());

  f[1] = 1;

  for (int i = 2; i <= n; i++) {
    for (auto j : v) {
      if (j > i)
        break;
      f[i] = (f[i] + f[i - j]) % H;
    }
  }
  cout << f[n];
}

#include <bits/stdc++.h>
#define name "test"
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define wrln cout << '\\n';
#define ii pair<int, int>
#define li pair<long long, int>
#define iii pair<int, ii>

using namespace std;
const int N = 2e5 + 100;
const int H = 998244353;

ll n, res, dem, sum, k;
ll f[N], d[N];

vector<ii> v;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen(name ".inp", "r")) {
    freopen(name ".inp", "r", stdin);
    freopen(name ".out", "w", stdout);
  }
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    v.pb({l, r});
  }

  f[1] = 1;
  d[1] = 1;
  f[0] = 0;
  d[0] = 0;

  for (int i = 2; i <= n; i++) {
    for (auto j : v) {
      int x = max(0, i - j.fi);
      int y = max(0, i - j.se - 1);

      f[i] = (f[i] + d[x] - d[y] + H) % H;
    }
    d[i] = (d[i - 1] + f[i]) % H;
  }
  cout << f[n];
}


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

int64_t Q = 998244353;

int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> p(K);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  vector<int64_t> dp(N + 1);
  vector<int64_t> rui(N + 1);
  dp[1] = 1;
  rui[1] = 1;
  for (int i = 2; i <= N; i++) {
    int64_t A = 0;
    for (int j = 0; j < K; j++) {
      int a, b;
      tie(a, b) = p[j];
      if (i <= a) {
        break;
      }
      A += rui[i - a] - rui[max(i - b - 1, 0)];
      A += Q;
      A %= Q;
    }
    dp[i] = A;
    rui[i] = (dp[i] + rui[i - 1]) % Q;
  }
  cout << dp[N] << endl;
}

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

int64_t Q = 998244353;

int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> p(K);
  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  vector<int64_t> dp(N + 1);
  vector<int64_t> rui(N + 1);
  dp[1] = 1;
  rui[1] = 1;
  for (int i = 2; i <= N; i++) {
    int64_t A = 0;
    for (int j = 0; j < K; j++) {
      int a, b;
      tie(a, b) = p[j];
      if (i <= a) {
        break;
      }
      A += rui[i - a] - rui[max(i - b - 1, 0)];
      A += Q;
      A %= Q;
    }
    dp[i] = A;
    rui[i] = (dp[i] + rui[i - 1]) % Q;
  }
  cout << dp[N] << endl;
}


// 2*10^9
// 9*10^18
//  __int128_t
#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long int
#define ll long long int

const ll M = 998244353;

// to handle when remainder is -neg we add + M
// but when rem is +pos that time also we add so use %M
// so it will work for both
ll mod(ll n) { return (n % M + M) % M; }
ll modAdd(ll a, ll b) { return mod(mod(a) + mod(b)); }
ll modMul(ll a, ll b) { return mod(mod(a) * mod(b)); }
ll modMinus(ll a, ll b) { return mod(mod(a) - mod(b)); }
ll modpow(ll x, ll n) {
  if (n == 0)
    return 1 % M;
  if (n == 1)
    return x % M;
  ll u = modpow(x, n / 2);
  u = modMul(u, u);
  if (n % 2)
    u = modMul(u, x);
  return u;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool isPrime(ll n) {
  int end = sqrt(n);
  for (int i = 2; i <= end; i++)
    if (n % i == 0)
      return false;
  return true;
}

int factors(int n) {
  int count = 0;
  int end = sqrt(n) - 1;

  for (int i = 1; i <= end; i++) {
    if (n % i == 0)
      count += 2;
  }
  if (n % (end + 1) == 0) {
    if (n / (end + 1) != (end + 1))
      count += 1;
    count += 1;
  }

  return count;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  // cin>>t;

  while (t--) {
    int n;
    cin >> n;

    vector<int> dp(n + 1);
    int k;
    cin >> k;

    vector<vector<int>> segment(k, vector<int>(2));
    for (int i = 0; i < k; i++)
      cin >> segment[i][0] >> segment[i][1];
    sort(segment.begin(), segment.end());

    dp[n] = 1;
    for (int i = n - 1; i >= 1; i--) {
      for (int j = 0; j < k; j++) {
        int start = i + segment[j][0];
        int end = i + segment[j][1];
        for (int k = start; k <= n && k <= end; k++)
          dp[i] = modAdd(dp[i], dp[k]);

        if (end >= n)
          break;
      }
    }
    cout << dp[1] << endl;
  }
  return 0;
}

// 2*10^9
// 9*10^18
//  __int128_t
#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long int
#define ll long long int

const ll M = 998244353;

// to handle when remainder is -neg we add + M
// but when rem is +pos that time also we add so use %M
// so it will work for both
ll mod(ll n) { return (n % M + M) % M; }
ll modAdd(ll a, ll b) { return mod(mod(a) + mod(b)); }
ll modMul(ll a, ll b) { return mod(mod(a) * mod(b)); }
ll modMinus(ll a, ll b) { return mod(mod(a) - mod(b)); }
ll modpow(ll x, ll n) {
  if (n == 0)
    return 1 % M;
  if (n == 1)
    return x % M;
  ll u = modpow(x, n / 2);
  u = modMul(u, u);
  if (n % 2)
    u = modMul(u, x);
  return u;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool isPrime(ll n) {
  int end = sqrt(n);
  for (int i = 2; i <= end; i++)
    if (n % i == 0)
      return false;
  return true;
}

int factors(int n) {
  int count = 0;
  int end = sqrt(n) - 1;

  for (int i = 1; i <= end; i++) {
    if (n % i == 0)
      count += 2;
  }
  if (n % (end + 1) == 0) {
    if (n / (end + 1) != (end + 1))
      count += 1;
    count += 1;
  }

  return count;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  // cin>>t;

  while (t--) {
    int n;
    cin >> n;

    vector<int> dp(n + 1);
    vector<int> suffix(n + 1);
    int k;
    cin >> k;

    vector<vector<int>> segment(k, vector<int>(2));
    for (int i = 0; i < k; i++)
      cin >> segment[i][0] >> segment[i][1];
    sort(segment.begin(), segment.end());

    dp[n] = 1;
    suffix[n] = 1;
    for (int i = n - 1; i >= 1; i--) {
      for (int j = 0; j < k; j++) {
        int start = i + segment[j][0];
        int end = i + segment[j][1];

        if (start <= n) {
          if (end < n)
            dp[i] = modAdd(dp[i], suffix[start] - suffix[end + 1]);
          else
            dp[i] = modAdd(dp[i], suffix[start]);
        }
      }
      suffix[i] = modAdd(dp[i], suffix[i + 1]);
    }
    cout << dp[1] << endl;
  }
  return 0;
}


#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  long long n, mod = 998244353;
  int k;
  cin >> n >> k;
  set<long long> s, next;
  vector<long long> df(n, 0);

  for (int i = 0; i < k; i++) {
    long long tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    for (long long j = tmp1; j < tmp2 + 1; j++) {
      s.insert(j);
    }
  }

  df[0] = 1;
  next.insert(0);

  for (long long i = 0; i < n; i++) {
    if (df[i] == 0) {
      continue;
    }

    next.erase(next.begin());

    for (auto itr = s.begin(); itr != s.end(); itr++) {
      if (i + *itr < n) {
        df[i + *itr] += df[i];
        df[i + *itr] %= mod;
        next.insert(i + *itr);
      } else {
        break;
      }
    }
  }

  cout << df[n - 1] << endl;
}

#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  long long n, mod = 998244353;
  int k;
  cin >> n >> k;
  set<long long> s, next;
  vector<long long> df(n + 1, 0);
  vector<long long> df_sum(n + 1, 0);
  vector<long long> left(k);
  vector<long long> right(k);

  for (int i = 0; i < k; i++) {
    long long tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    for (long long j = tmp1; j < tmp2 + 1; j++) {
      s.insert(j);
    }
    left[i] = tmp1;
    right[i] = tmp2;
  }

  df[1] = 1;
  df_sum[0] = 0;
  df_sum[1] = 1;
  // next.insert(0);

  for (long long i = 2; i <= n; i++) {
    /*if (df[i] == 0) {
        continue;
    }*/

    // next.erase(next.begin());

    /*for (auto itr = s.begin(); itr != s.end(); itr++) {
        if (i + *itr < n) {
            df[i + *itr] += df[i];
            df[i + *itr] %= mod;
            // next.insert(i + *itr);
        } else {
            break;
        }
    }*/

    for (long long j = 0; j < k; j++) {
      int lefti = i - right[j];
      int righti = i - left[j];
      if (righti < 0)
        continue;
      lefti = max(lefti, 1);
      df[i] += df_sum[righti] - df_sum[lefti - 1];
      df[i] %= mod;
    }

    df_sum[i] = df_sum[i - 1] + df[i];
    // cout << df_sum[i] << endl;
  }

  /*for (auto itr = s.begin(); itr != s.end(); itr++) {
      int now=0
  }*/

  cout << df[n] << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//(a+b-1)/b
// priority_queue<ll, vector<ll>, greater<ll>> q;

signed main() {
  // cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  vl nx(0);
  rep(i, 0, k) {
    ll a, b;
    cin >> a >> b;
    rep(j, a, b + 1) nx.push_back(j);
  }
  vl dp(n + 1);
  dp[1] = 1;
  rep(i, 1, n) {
    for (auto c : nx) {
      if (i + c <= n) {
        dp[i + c] += dp[i];
        dp[i + c] %= 998244353;
      }
    }
  }
  cout << dp[n] << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//(a+b-1)/b
// priority_queue<ll, vector<ll>, greater<ll>> q;
vector<pl> vec(0);

class SegmentTree {
public:
  vector<ll> seg;
  ll len;
  SegmentTree(ll n) {
    len = n;
    seg.resize(2 * n);
  }
  void add(ll ind, ll x) { // 1indexed
    ind += len;
    seg[ind] += x;
    while (true) {
      ind /= 2;
      if (ind == 0)
        break;
      seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];
      seg[ind] %= 998244353;
    }
  }
  ll get_sum(ll l, ll r) { // 1indexed
    ll ans = 0;
    l += len;
    r += len;
    while (l < r) {
      if (l % 2 == 1) {
        ans += seg[l];
        l++;
      }
      l /= 2;
      if (r % 2 == 1) {
        ans += seg[r - 1];
        --r;
      }
      r /= 2;
    }
    return ans;
  }
};

signed main() {
  // cout << fixed << setprecision(10);
  ll n, k;
  cin >> n >> k;
  SegmentTree s(200200);
  s.add(1, 1);
  rep(i, 0, k) {
    ll a, b;
    cin >> a >> b;
    vec.push_back(pl(a, b));
  }
  rep(i, 1, n + 1) {
    ll sum = 0;
    rep(j, 0, k) {
      if (i - vec[j].first < 1)
        continue;
      ll l = max((ll)1, i - vec[j].second);
      ll r = i - vec[j].first + 1;
      sum += s.get_sum(l, r);
      sum %= 998244353;
    }
    s.add(i, sum);
  }
  cout << s.get_sum(n, n + 1) << endl;

  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;

int main(int argc, char const *argv[]) {
  int mod = 998244353;
  int n, k;
  cin >> n >> k;
  // int step[200010] = {};
  // cout << step[3] << endl;
  int l[15], r[15];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }

  sort(l, l + k);
  sort(r, r + k);

  /*
  for (int i = 0; i < k; i++)
  {
      cin >> l >> r;
      for (int j = l; j <= r; j++)
      {
          step[j] = 1;
      }
  }
  */
  int dp[200010] = {};
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (l[j] >= i)
        break;
      for (int m = l[j]; m <= min(i, r[j]); m++) {
        dp[i] += dp[i - m];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n] << endl;

  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;

int main(int argc, char const *argv[]) {
  int mod = 998244353;
  int n, k;
  cin >> n >> k;
  int l[15], r[15];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }

  sort(l, l + k);
  sort(r, r + k);

  long long int dp[200010] = {};
  dp[1] = 1;
  if (l[0] == 1)
    dp[2] = 1;
  for (int i = 3; i <= n; i++) {
    dp[i] = dp[i - 1];
    for (int j = 0; j < k; j++) {
      if (i - l[j] - 1 >= 0) {
        dp[i] += dp[i - l[j]];
        if (i - r[j] - 1 >= 1)
          dp[i] -= dp[i - r[j] - 1];
        if (dp[i] < 0)
          dp[i] += mod;
        dp[i] %= mod;
      }
    }
    // cout << dp[i] << endl;
  }
  cout << dp[n] << endl;

  return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
#define fa fflush(stdout);
#define mp make_pair
using namespace std;
void data() {
#ifdef NURS
  freopen("main.in", "r", stdin);
  freopen("main.out", "w", stdout);
#endif
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
}
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};

const int N = 1e6 + 100;
const ll mod = 1e6 + 3;
const ll big = 1e9;
const ll p = 27;

ll dp[N];
int ok[N];
int main() {
  data();
  // freopen("substr3.in","r",stdin);
  // freopen("substr3.out","w",stdout);
  int n, k;
  cin >> n >> k;
  dp[1] = 1;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      ok[j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dp[i] > 0) {
      for (int j = 1; j + i <= n; j++) {
        if (ok[j]) {
          dp[i + j] += dp[i];
          dp[i + j] %= 998244353LL;
        }
      }
    }
  }
  cout << dp[n];
}

#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
#define fa fflush(stdout);
#define mp make_pair
using namespace std;
void data() {
#ifdef NURS
  freopen("main.in", "r", stdin);
  freopen("main.out", "w", stdout);
#endif
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
}
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};

const int N = 1e6 + 100;
const ll mod = 1e6 + 3;
const ll big = 1e9;
const ll p = 27;

ll dp[N];
ll ok[N];
int main() {
  data();
  // freopen("substr3.in","r",stdin);
  // freopen("substr3.out","w",stdout);
  int n, k;
  cin >> n >> k;
  dp[1] = 1;
  int l[k + 1], r[k + 1];
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 1; i <= n; i++) {
    ok[i] += ok[i - 1];
    dp[i] += ok[i];
    dp[i] %= 998244353;
    if (dp[i] > 0) {
      for (int j = 1; j <= k; j++) {
        if (i + l[j] <= n) {
          ok[i + l[j]] += dp[i];
          ok[i + l[j]] %= 998244353;
          if (i + r[j] + 1 <= n) {
            ok[min(n + 1, i + r[j] + 1)] -= dp[i];
          }
        }
      }
    }
  }
  cout << dp[n];
}