#include <bits/stdc++.h>
using namespace std;
const int MAX = 100010;
const long long MOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-7;
const int LOG = ceil(log2(MAX));
namespace seg {
long long seg[2 * MAX], lazy[2 * MAX];
int n;
long long junta(long long a, long long b) { return (a + b) % MOD; }
void poe(int p, long long x, int tam, bool prop = 1) {
  seg[p] += x * tam;
  seg[p] %= MOD;
  if (prop and p < n) lazy[p] += x;
}
void sobe(int p) {
  for (int tam = 2; p /= 2; tam *= 2) {
    seg[p] = junta(seg[2 * p], seg[2 * p + 1]);
    poe(p, lazy[p], tam, 0);
  }
}
void prop(int p) {
  int tam = 1 << (LOG - 1);
  for (int s = LOG; s; s--, tam /= 2) {
    int i = p >> s;
    if (lazy[i]) {
      poe(2 * i, lazy[i], tam);
      poe(2 * i + 1, lazy[i], tam);
      lazy[i] = 0;
    }
  }
}
void build(int n2) {
  n = n2;
  for (int i = n - 1; i; i--) seg[i] = junta(seg[2 * i], seg[2 * i + 1]);
  for (int i = 0; i < 2 * n; i++) lazy[i] = 0;
}
long long query(int a, int b) {
  long long ret = 0;
  for (prop(a += n), prop(b += n); a <= b; ++a /= 2, --b /= 2) {
    if (a % 2 == 1) ret = junta(ret, seg[a]);
    if (b % 2 == 0) ret = junta(ret, seg[b]);
  }
  return ret;
}
void update(int a, int b, int x) {
  int a2 = a += n, b2 = b += n, tam = 1;
  for (; a <= b; ++a /= 2, --b /= 2, tam *= 2) {
    if (a % 2 == 1) poe(a, x, tam);
    if (b % 2 == 0) poe(b, x, tam);
  }
  sobe(a2), sobe(b2);
}
};  // namespace seg
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k, l, r;
  cin >> n >> k;
  vector<pair<int, int> > S;
  seg::build(n + 10);
  seg::update(1, 1, 1);
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    S.push_back({l, r});
  }
  for (int i = 1; i <= n; i++) {
    long long val = seg::query(i, i);
    for (auto s : S)
      seg::update(min(i + s.first, n + 1), min(i + s.second, n + 1), val);
  }
  cout << seg::query(n, n) << '\n';
  return 0;
}
