#include <bits/stdc++.h>
using namespace std;
int64_t Q = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> p(K);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  vector<int64_t> dp(N + 1);
  vector<int64_t> rui(N + 1);
  dp[1] = 1;
  rui[1] = 1;
  for (int i = 2; i <= N; i++) {
    int64_t A = 0;
    for (int j = 0; j < K; j++) {
      int a, b;
      tie(a, b) = p[j];
      if (i <= a) {
        break;
      }
      A += rui[i - a] - rui[max(i - b - 1, 0)];
      A += Q;
      A %= Q;
    }
    dp[i] = A;
    rui[i] = (dp[i] + rui[i - 1]) % Q;
  }
  cout << dp[N] << endl;
}
