#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const long long mod = 998244353;
template <class T>
struct SegTree {
  int n;
  vector<T> node;
  function<T(T, T)> f;
  T iniV;
  SegTree(vector<T> v, function<T(T, T)> f, T iniV) : iniV(iniV), f(f) {
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(n * 2 - 1, iniV);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--) {
      node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }
  T getOneVal(int x) { return node[x + n - 1]; }
  void update(int x, T val) {
    x += n - 1;
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = f(node[x * 2 + 1], node[x * 2 + 2]);
    }
  }
  T getval(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return iniV;
    if (a <= l && r <= b) return node[k];
    T vl = getval(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = getval(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};
long long ff(long long a, long long b) { return (a + b) % mod; }
int main() {
  int N, K;
  cin >> N >> K;
  int L[K], R[K];
  for (int i = 0; i < K; i++) cin >> L[i] >> R[i];
  vector<long long> dp(N + 1, 0LL);
  SegTree<long long> seg(dp, ff, 0LL);
  seg.update(1, 1LL);
  for (int i = 2; i <= N; i++) {
    lint val = 0LL;
    for (int j = 0; j < K; j++) {
      int idl;
      int idr;
      val += seg.getval(i - R[j], i - L[j] + 1);
    }
    seg.update(i, val);
  }
  cout << seg.getOneVal(N) << endl;
  return 0;
}
