#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353;
long long int power(long long int a, long long int b, long long int mod) {
  a %= mod;
  long long int ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    ;
    if (ret >= mod) ret %= mod;
    if (a >= mod) a %= mod;
    b >>= 1;
  }
  return ret;
}
template <class T>
void read(T& x) {
  cin >> x;
}
template <class T, class... U>
void read(T& x, U&... u) {
  read(x);
  read(u...);
}
template <class A>
void read(vector<A>& v) {
  for (auto& it : v) read(it);
}
template <class A>
void print(A x) {
  cout << x;
}
template <class A>
void printl(A x) {
  cout << x << endl;
}
template <class A>
void print(vector<A>& v) {
  for (auto& it : v) {
    print(it);
    cout << ' ';
  }
  cout << '\n';
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  set<long long int> indexes;
  for (long long int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    for (long long int j = x; j < y + 1; j++) indexes.insert(j);
  }
  vector<long long int> coins{indexes.begin(), indexes.end()};
  vector<long long int> moves(n + 5, 0);
  moves[1] = 1;
  for (long long int i = 2; i <= n; i++) {
    for (auto it : indexes) {
      if (i - it > 0) {
        moves[i] = (moves[i] + moves[i - it]) % mod;
      }
    }
  }
  cout << moves[n] % mod << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
