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