#include <bits/stdc++.h>
using namespace std;
struct cmp {
  bool operator()(long long a, long long b) { return (a > b); }
};
long long ceil(const long long &a, const long long &b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
long long mod = 998244353;
const long long N = 100005;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v;
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  map<long long, long long> m;
  for (long long i = 0; i < k; i++) {
    for (long long j = v[i].first; j <= v[i].second; j++) {
      m[j]++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (m[i] > 0) {
      a.push_back(i);
    }
  }
  sort(a.begin(), a.end());
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[a[0]] = 1;
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < (long long)a.size(); j++) {
      if (a[j] <= i) dp[i] = (dp[i] % mod + (dp[i - a[j]]) % mod) % mod;
    }
  }
  cout << dp[n];
  return 0;
}
