#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int mod = 998244353;
  vector<pair<int, int>> steps;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    steps.push_back({x, y});
  }
  sort(steps.begin(), steps.end());
  vector<int> dp(n);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = i - steps[j].second;
      int r = i - steps[j].first;
      if (r >= 0) {
        dp[i] = (dp[i] + dp[r]) % mod;
      }
      if (l > 0) {
        dp[i] = (dp[i] - dp[l - 1] + mod) % mod;
      }
    }
    if (i != n - 1) {
      dp[i] = (dp[i] + dp[i - 1]) % mod;
    }
  }
  cout << dp[n - 1];
  return 0;
}
