#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> x(n, 0);
  for (long long i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    l--;
    x[l]++;
    x[r]--;
  }
  for (long long i = 0; i + 1 < n; ++i) {
    x[i + 1] += x[i];
  }
  vector<long long> s;
  for (long long i = 0; i < n; ++i) {
    if (x[i]) {
      s.push_back(i + 1);
    }
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  long long smax = s.size();
  for (long long i = 2; i < n + 1; ++i) {
    for (long long j = 0; j < smax; ++j) {
      long long r = i - s[j];
      if (r <= 0) {
        continue;
      }
      if (dp[r]) {
        dp[i] = (dp[i] + dp[r]) % mod;
      }
    }
  }
  dp[n] %= mod;
  cout << dp[n] << endl;
  return 0;
}
