#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> ls(k), rs(k);
  for (int64_t i = 0; i < k; i++) {
    cin >> ls[i] >> rs[i];
  }
  int64_t mod = 998244353;
  vector<int64_t> dp(n + 1, 0);
  dp[1] = 1;
  for (int64_t i = 0; i < n; i++) {
    vector<int64_t> imos(n + 1, 0);
    for (int64_t j = 0; j < k; j++) {
      if (i + ls[j] <= n) {
        (imos[i + ls[j]] += dp[i]) %= mod;
      }
      if (i + rs[j] + 1 <= n) {
        (imos[i + rs[j] + 1] += mod - dp[i]) %= mod;
      }
    }
    for (int64_t j = 1; j <= n; j++) {
      (imos[j] += imos[j - 1]) %= mod;
    }
    for (int64_t j = 0; j <= n; j++) {
      (dp[j] += imos[j]) %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
