#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
const int INF = 0x3f3f3f3f;
long long A[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  set<int> st;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) st.insert(j);
  }
  A[*st.begin()] = 1;
  for (int i = *st.begin() + 1; i <= n; ++i) {
    for (auto x : st) {
      int pos = i - x;
      if (pos < 0) pos = 0;
      A[i] += A[pos];
      A[i] %= Mod;
    }
  }
  cout << A[n] << endl;
  return 0;
}
