#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int q = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(K), r(K);
  for (int i = 0; i < (K); ++i) {
    cin >> l[i] >> r[i];
  }
  vector<int> dp(N, 0), dp_sum(N, 0);
  dp[0] = 1;
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (K); ++j) {
      int li = max(0, i - l[j]);
      int ri = i - r[j];
      if (ri < 0) continue;
      dp[j] += dp_sum[ri] - dp_sum[li];
      dp[j] %= q;
    }
    dp_sum[i] = (dp_sum[i - 1] + dp[i]) % q;
  }
  cout << dp[N - 1] << endl;
  return 0;
}
