#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; ++i) cin >> l[i] >> r[i];
  vector<long long> dp(n, 0), sdp(n + 1, 0);
  dp[0] = sdp[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      long long left = max(0, i - r[j]);
      long long right = max(0, i - l[j] + 1);
      dp[i] += sdp[right] - sdp[left];
    }
    sdp[i + 1] = sdp[i] + dp[i];
  }
  cout << dp[n - 1] % mod;
  return 0;
}
