#include <bits/stdc++.h>
using namespace std;
int vector_finder(vector<int> vec, int number);
int main() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> s;
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (l[j] <= i && i <= r[j]) s.push_back(i);
    if (r[j] < i) j++;
  }
  int dp[n + 1];
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (int j = 1; j < i; j++) {
      if (vector_finder(s, i - j)) dp[i] += dp[j];
    }
    if (dp[i] > 998244353) dp[i] %= 998244353;
  }
  cout << dp[n];
  return 0;
}
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {
    return 1;
  } else {
    return 0;
  }
}
