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