#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
struct item {
  ll val;
};
class SegTree {
 public:
  int size;
  vector<item> values;
  SegTree(int n) {
    size = 1;
    while (size < n) size *= 2;
    values.resize(size * 2 - 1);
  }
  item NEUTRAL_ELEMENT = {0};
  item single(ll val) { return {val}; }
  item merge(item a, item b) { return {(a.val + b.val) % mod}; }
  void build(vector<ll>& a) { build(a, 0, 0, size); };
  void build(vector<ll>& a, int node, int nodeL, int nodeR) {
    if (nodeR - nodeL == 1) {
      if (nodeL < a.size()) values[node] = single(a[nodeL]);
      return;
    }
    int m = (nodeL + nodeR) / 2;
    build(a, node * 2 + 1, nodeL, m);
    build(a, node * 2 + 2, m, nodeR);
    values[node] = merge(values[node * 2 + 1], values[node * 2 + 2]);
  }
  void set(int index, int val) { set(index, val, 0, 0, size); }
  void set(int index, int val, int node, int nodeL, int nodeR) {
    if (nodeR - nodeL == 1) {
      values[node] = single(val);
      return;
    }
    int m = (nodeL + nodeR) / 2;
    if (index < m)
      set(index, val, node * 2 + 1, nodeL, m);
    else
      set(index, val, node * 2 + 2, m, nodeR);
    values[node] = merge(values[node * 2 + 1], values[node * 2 + 2]);
  }
  void add(int index, int val) { add(index, val, 0, 0, size); }
  void add(int index, int val, int node, int nodeL, int nodeR) {
    if (nodeR - nodeL == 1) {
      values[node].val += val;
      return;
    }
    int m = (nodeL + nodeR) / 2;
    if (index < m)
      add(index, val, node * 2 + 1, nodeL, m);
    else
      add(index, val, node * 2 + 2, m, nodeR);
    values[node] = merge(values[node * 2 + 1], values[node * 2 + 2]);
  }
  item calc(int l, int r) { return calc(l, r, 0, 0, size); }
  item calc(int l, int r, int node, int nodeL, int nodeR) {
    if (r <= nodeL || l >= nodeR) return NEUTRAL_ELEMENT;
    if (l <= nodeL && nodeR <= r) return values[node];
    int m = (nodeL + nodeR) / 2;
    return merge(calc(l, r, node * 2 + 1, nodeL, m),
                 calc(l, r, node * 2 + 2, m, nodeR));
  }
};
void solve() {
  vector<ll> dp(200001);
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> l(k), r(k);
  for (int(i) = 0; (i) < (n); (i)++) cin >> l[i] >> r[i];
  dp[1] = 1LL;
  SegTree st(n + 1);
  st.set(1, 1);
  st.set(2, -1);
  for (int cur = 1; cur < n; cur++) {
    ll addValue = st.calc(0, cur + 1).val;
    for (int(i) = 0; (i) < (k); (i)++) {
      st.add(l[i] + cur, addValue);
      st.add(r[i] + 1 + cur, -1 * addValue);
    }
  }
  cout << st.calc(0, n + 1).val;
}
int main() {
  int T;
  T = 1;
  while (T--) {
    solve();
    cout << endl;
  }
}
