#include <bits/stdc++.h>
using ll = long long;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
using namespace std;
const int mod = 998244353;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  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 {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  bool operator>(const mint a) const {
    mint res(*this);
    return res.x > a.x;
  }
  bool operator<(const mint a) const {
    mint res(*this);
    return res.x < a.x;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
constexpr int premax = 200020;
std::array<mint, premax> f, rf;
bool mymodflag = false;
mint nCk(int n, int k) {
  if (n == k) return mint(1);
  if (n < k) return mint(0);
  if (!mymodflag) {
    f[0] = 1;
    for (int i = 1; i < premax; i++) f[i] = f[i - 1] * i;
    rf[premax - 1] = f[premax - 1].pow(mod - 2);
    for (int i = premax - 2; i >= 0; i--) rf[i] = rf[i + 1] * (i + 1);
    mymodflag = true;
  }
  return f[n] * rf[n - k] * rf[k];
}
mint nPk(int n, int k) {
  if (n < k) return mint(0);
  if (!mymodflag) {
    f[0] = 1;
    for (int i = 1; i < premax; i++) f[i] = f[i - 1] * i;
    rf[premax - 1] = f[premax - 1].pow(mod - 2);
    for (int i = premax - 2; i >= 0; i--) rf[i] = rf[i + 1] * (i + 1);
    mymodflag = true;
  }
  return f[n] * rf[n - k];
}
struct LazySegmentTree {
 private:
  int n;
  vector<mint> node, lazy;

 public:
  LazySegmentTree(vector<mint> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
  }
  void eval(int k, int l, int r) {
    if (lazy[k].x != 0) {
      node[k] += lazy[k];
      if (r - l > 1) {
        lazy[2 * k + 1] += lazy[k] / 2;
        lazy[2 * k + 2] += lazy[k] / 2;
      }
      lazy[k] = 0;
    }
  }
  void add(int a, int b, mint x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      mint tmp = r - l;
      lazy[k] += tmp * x;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = node[2 * k + 1] + node[2 * k + 2];
    }
  }
  mint getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return node[k];
    mint vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    mint vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
  }
};
int main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, k;
  std::cin >> n >> k;
  LazySegmentTree seg(std::vector<mint>(n + 2, 0));
  seg.add(1, 2, 1);
  std::vector<int> L(k), R(k);
  for (int i = 0; i < (int)(k); i++) std::cin >> L[i] >> R[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (int)(k); j++) {
      if (i + L[j] > n) continue;
      int right = std::min(n + 1, i + R[j] + 1);
      mint v = seg.getsum(i, i + 1);
      seg.add(i + L[j], right, v);
    }
  }
  mint ans = seg.getsum(n, n + 1);
  std::cout << ans.x << std::endl;
  return 0;
}
