#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
const ll mod = 998244353;
struct RSQ_RAQ {
  int n;
  vector<ll> node, lazy;
  RSQ_RAQ(int sz) {
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
  }
  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      lazy[k] %= mod;
      node[k] = (node[k] + lazy[k]) % mod;
      if (r - l > 0) {
        ll tmp = (lazy[k] / 2) % mod;
        lazy[2 * k + 1] = (lazy[2 * k + 1] + tmp) % mod;
        lazy[2 * k + 2] = (lazy[2 * k + 2] + tmp) % mod;
      }
      lazy[k] = 0;
    }
  }
  void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
    x %= mod;
    if (r < 0) r = n - 1;
    eval(k, l, r);
    if (b < l || r < a) return;
    if (a <= l && r <= b) {
      ll tmp = ((r - l + 1) * x) % mod;
      lazy[k] = (lazy[k] + tmp) % mod;
      lazy[k] %= mod;
      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 + 1, r);
      node[k] = (node[2 * k + 1] + node[2 * k + 2]) % mod;
    }
  }
  ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n - 1;
    eval(k, l, r);
    if (b < l || r < a) return 0;
    if (a <= l && r <= b) return node[k];
    ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2 + 1, r);
    return (vl + vr) % mod;
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  RSQ_RAQ seg(n + 10);
  vl l(n), r(n);
  for (int(i) = (0); (i) < (k); (i)++) {
    cin >> l[i] >> r[i];
  }
  seg.add(0, 0, 1);
  for (int(i) = (1); (i) < (n + 9); (i)++) {
    for (int(j) = (0); (j) < (k); (j)++) {
      seg.add((i - 1) + l[j], (i - 1) + r[j], seg.getsum(i - 1, i - 1) % mod);
    }
  }
  cout << seg.getsum(n - 1, n - 1) % mod << endl;
  return 0;
}
