#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> jumps;
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    jumps.push_back({a, b});
  }
  vector<int> dp(n + 1, 0);
  if (n == 1) {
    cout << 1;
  } else {
    int ans = 0;
    dp[1] = 1;
    for (int i = 2; i <= n; ++i) {
      for (auto& p : jumps) {
        int jumpMinPos = i - p.second;
        int jumpMaxPos = i - p.first;
        int rangeMin = max(1, jumpMinPos);
        int rangeMax = min(i, jumpMaxPos);
        if ((rangeMin <= rangeMax) and (rangeMin >= 1) and (rangeMax <= i)) {
          int toAdd = dp[rangeMax] - dp[rangeMin - 1];
          dp[i] = (dp[i] + toAdd) % 998244353;
        }
      }
      dp[i] = (dp[i] + dp[i - 1]) % 998244353;
    }
    cout << dp[n] - dp[n - 1];
  }
  return 0;
}
