#include <bits/stdc++.h>
using namespace std;
long long dp[200005], pre[200005];
long long mod = 998244353;
int main() {
  long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    v.push_back(make_pair(l, r));
  }
  dp[1] = pre[1] = 1;
  for (long i = 2; i <= n; i++) {
    long lmt = i - 1;
    long long ways = 0;
    for (int j = 0; j < k; j++) {
      long l = v[j].first, r = v[j].second;
      if (l > lmt) continue;
      long new_r = min(lmt, r);
      ways = (ways + ((pre[i - l] - pre[i - new_r - 1]) % mod)) % mod;
    }
    dp[i] = ways;
    pre[i] = (ways + pre[i - 1]) % mod;
  }
  cout << dp[n];
  return 0;
}
