#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
using ll = long long;
template <typename T>
class LazySegmentTree {
 private:
  std::vector<T> node, lazy;
  std::function<T(T, T)> f;
  std::function<T(T, T)> g;
  std::function<T(T, int)> pow;
  T f_ide;
  T g_ide;
  int size;

 public:
  LazySegmentTree(int n, std::function<T(T, T)> f, std::function<T(T, T)> g,
                  T f_ide, T g_ide)
      : f(f), g(g), f_ide(f_ide), g_ide(g_ide) {
    init(n);
    pow = [=](T a, int k) {
      T ans = g_ide;
      while (k > 0) {
        if (k & 1) ans = g(ans, a);
        a = g(a, a);
        k >>= 1;
      }
      return ans;
    };
  }
  LazySegmentTree(int n, std::function<T(T, T)> f, std::function<T(T, T)> g,
                  std::function<T(T, int)> pow, T f_ide, T g_ide)
      : f(f), g(g), pow(pow), f_ide(f_ide), g_ide(g_ide) {
    init(n);
  }
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    node = std::vector<T>(2 * size - 1, f_ide);
    lazy = std::vector<T>(2 * size - 1, g_ide);
  }
  void eval(int k, int l, int r) {
    node[k] = g(node[k], pow(lazy[k], r - l));
    if (r - l >= 2) {
      lazy[2 * k + 1] = g(lazy[2 * k + 1], lazy[k]);
      lazy[2 * k + 2] = g(lazy[2 * k + 2], lazy[k]);
    }
    lazy[k] = g_ide;
  }
  void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = size;
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] = g(lazy[k], x);
      eval(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      eval(2 * k + 1, l, (l + r) / 2);
      eval(2 * k + 2, (l + r) / 2, r);
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  T get(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = size;
    if (r <= a || b <= l) return f_ide;
    eval(k, l, r);
    if (a <= l && r <= b) {
      return node[k];
    } else {
      T result_left = get(a, b, 2 * k + 1, l, (l + r) / 2);
      T result_right = get(a, b, 2 * k + 2, (l + r) / 2, r);
      return f(result_left, result_right);
    }
  }
};
void solve(long long N, long long K, std::vector<long long> L,
           std::vector<long long> R) {
  std::function<long long(long long, long long)> f =
      [](long long a, long long b) { return (a + b) % MOD; };
  std::function<long long(long long, int)> pow = [](long long a, int b) {
    return (a * b) % MOD;
  };
  auto g = f;
  LazySegmentTree<long long> Seg(N, f, g, pow, 0, 0);
  Seg.update(0, 1, 1);
  for (int i = 0; i < N; i++) {
    for (int k = 0; k < K; k++) {
      ll l = i + L[k];
      ll r = i + R[k] + 1;
      ll x = Seg.get(i, i + 1);
      if (l >= N) {
        continue;
      }
      Seg.update(l, min(r, N), x);
    }
  }
  cout << Seg.get(N - 1, N) << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> L(K);
  std::vector<long long> R(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve(N, K, std::move(L), std::move(R));
  return 0;
}
