#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
long long gcd(long long a, long long b) {
  if (b > a) {
    long long tmp = b;
    b = a;
    a = tmp;
  }
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
template <typename T>
struct SegmentTree {
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int newn, F f, T t) : f(f), unit(t) { init(newn); }
  SegmentTree(const vector<T> &v, F f, T t) : f(f), unit(t) {
    int n_ = v.size();
    init(n_);
    for (int i = 0; i < n_; i++) dat[n + i] = v[i];
    for (int i = n - 1; i; i--) {
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }
  }
  void init(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, unit);
  }
  void update(int k, T x) {
    dat[k += n] = x;
    while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> L(k), R(k);
  for (int i = 0; i < k; i++) cin >> L[i] >> R[i];
  auto f = [](long long l, long long r) {
    return (r + l + 998244353) % 998244353;
  };
  SegmentTree<long long> seg = SegmentTree<long long>(n + 1, f, 0);
  seg.update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = i - R[j];
      int r = i - L[j];
      l = min(l, n);
      r = min(r, n);
      long long now = seg.query(i, i + 1);
      long long t = seg.query(l, r + 1);
      seg.update(i, (now + t) % 998244353);
    }
  }
  cout << seg.query(n, n + 1) << endl;
  return 0;
}
