#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
template <typename T>
void debug(vector<T> x) {
  for (auto e : x) {
    cout << e << " ";
  }
  cout << "\n";
}
long long lazy[400005] = {0};
long long queryLazy(long long *tree, long long ss, long long se, long long qs,
                    long long qe, long long inc, long long index) {
  if (lazy[index] != 0) {
    tree[index] += lazy[index];
    if (ss != se) {
      lazy[2 * index] = (lazy[2 * index] + lazy[index]) % mod;
      lazy[2 * index + 1] = (lazy[2 * index + 1] + lazy[index]) % mod;
    }
    lazy[index] = 0;
  }
  if (ss > qe || se < qs) {
    return 0;
  }
  if (ss >= qs && se <= qe) {
    return tree[index];
  }
  long long mid = (ss + se) / 2;
  long long left = queryLazy(tree, ss, mid, qs, qe, inc, 2 * index);
  long long right = queryLazy(tree, mid + 1, se, qs, qe, inc, 2 * index + 1);
  return ((left + right) % mod);
}
void buildTree(vector<long long> &a, long long s, long long e, long long *tree,
               long long index) {
  if (s == e) {
    tree[index] = a[s];
    return;
  }
  long long mid = (s + e) / 2;
  buildTree(a, s, mid, tree, 2 * index);
  buildTree(a, mid + 1, e, tree, 2 * index + 1);
  tree[index] = (tree[2 * index] + tree[2 * index + 1]) % mod;
  return;
}
void updateRangeLazy(long long *tree, long long ss, long long se, long long l,
                     long long r, long long inc, long long index) {
  if (lazy[index] != 0) {
    tree[index] = (tree[index] + lazy[index]) % mod;
    if (ss != se) {
      lazy[2 * index] = (lazy[2 * index] + lazy[index]) % mod;
      lazy[2 * index + 1] = (lazy[2 * index + 1] + lazy[index]) % mod;
    }
    lazy[index] = 0;
  }
  if (r < ss || l > se) {
    return;
  }
  if (ss >= l && se <= r) {
    tree[index] = (tree[index] + inc) % mod;
    if (ss != se) {
      lazy[2 * index] = (lazy[2 * index] + inc) % mod;
      lazy[2 * index + 1] = (lazy[2 * index + 1] + inc) % mod;
    }
    return;
  }
  long long mid = (ss + se) / 2;
  updateRangeLazy(tree, ss, mid, l, r, inc, 2 * index);
  updateRangeLazy(tree, mid + 1, se, l, r, inc, 2 * index + 1);
  tree[index] = (tree[2 * index] + tree[2 * index + 1]) % mod;
  return;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  long long *tree = new long long[4 * n + 4];
  buildTree(dp, 1, n, tree, 1);
  vector<bool> helper(n + 1);
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) helper[j] = true;
  }
  vector<pair<long long, long long>> steps;
  bool start = false;
  long long startIdx = -1;
  for (long long i = 1; i <= n; i++) {
    if (helper[i]) {
      if (!start) {
        start = true;
        startIdx = i;
      }
    } else {
      if (start) {
        steps.push_back(make_pair(startIdx, i - 1));
        start = false;
      }
    }
  }
  if (start) {
    steps.push_back(make_pair(startIdx, n));
    start = false;
  }
  long long m = steps.size();
  for (long long i = 1; i < n; i++) {
    long long inc = queryLazy(tree, 1, n, i, i, 0, 1);
    for (long long j = 0; j < m; j++) {
      if (i + steps[i].first <= n) {
        long long l = i + steps[j].first, r = min(i + steps[j].second, n);
        updateRangeLazy(tree, 1, n, l, r, inc, 1);
      }
    }
  }
  cout << "\n";
  long long ans = queryLazy(tree, 1, n, n, n, 0, 1);
  cout << ans;
  cout << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
