#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<long long>>;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const double PI = 3.1415926535897932;
struct LazySegmentTree {
 public:
  int n;
  vector<long long> node, lazy;
  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      node[k] += lazy[k];
      if (r - l > 1) {
        lazy[2 * k + 1] += lazy[k] / 2;
        lazy[2 * k + 2] += lazy[k] / 2;
      }
      lazy[k] = 0;
    }
  }
  void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += (r - l) * x;
      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, r);
      node[k] = node[2 * k + 1] + node[2 * k + 2];
    }
  }
  long long getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return 0;
    eval(k, l, r);
    if (a <= l && r <= b) return node[k];
    long long vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    long long vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
  }

 public:
  LazySegmentTree(vector<long long> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
  }
};
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  long long n, k;
  cin >> n >> k;
  vector<long long> l(k), r(k);
  vector<long long> ok(n, 0);
  for (long long i = 0; i < (k); i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i] - 1; j < r[i]; j++) {
      ok[j] = 1;
    }
  }
  vector<long long> ans(n + 2, 0);
  ans[1] = 1;
  LazySegmentTree tr(ans);
  for (int i = 1; i < n; i++) {
    if (tr.getsum(i, i + 1) == 0) continue;
    for (int j = 0; j < k; j++) {
      tr.add(min(i + l[j], n + 1), min(i + r[j] + 1, n + 2),
             tr.getsum(i, i + 1));
    }
  }
  cout << tr.getsum(n, n + 1) % MOD2 << endl;
  return 0;
}
