#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

template <typename T, T M> class modint {
public:
  T v{};
  modint(T v) : v{v % M + (((v % M) < 0) ? M : 0)} {}
  modint operator+(modint other) { return modint{v + other.v}; }
  modint operator-(modint other) { return modint{v - other.v}; }
  modint operator*(modint other) { return modint{v * other.v}; }
  modint operator/(modint other) { return modint{v / other.v}; }
  modint operator+=(modint other) {
    *this = *this + other;
    return *this;
  }
  modint operator-=(modint other) {
    *this = *this - other;
    return *this;
  }
  modint operator*=(modint other) {
    *this = *this * other;
    return *this;
  }
  modint operator/=(modint other) {
    *this = *this / other;
    return *this;
  }
}

void run() {
  const i64 mod{998244353};
  i64 n, k;
  cin >> n >> k;
  vector<i64> ls(k), rs(k);
  rep(i, 0, k) { cin >> ls[i] >> rs[i]; }
  vector<modint<i64, mod>> counts(n + 1);
  vector<modint<i64, mod>> incs(n + 1);
  incs[1] = 1;
  incs[2] = -1;
  rep(i, 1, n + 1) {
    counts[i] = (counts[i - 1] + incs[i]);
    rep(ik, 0, k) {
      i64 il{i + ls[ik]}, ir{i + rs[ik] + 1};
      if (il < n + 1) {
        incs[il] += counts[i];
        if (ir < n + 1) {
          incs[ir] -= counts[i];
        }
      }
    }
  }
  cout << counts[n] << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}
