#include <bits/stdc++.h>
using namespace std;
int64_t R = 1;
void solution() {
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> v, ve(200010);
  for (int i = 0; i < k; i++) {
    int64_t x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) {
      v.push_back(i);
    }
  }
  vector<int64_t> dp(n);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (v).size(); j++) {
      if (i - v[j] >= 0) {
        dp[i] += dp[i - v[j]] % 998244353;
        dp[i] = dp[i] % 998244353;
      }
    }
  }
  cout << dp[n - 1] << "\n";
}
int main() {
  for (long long int i = 0; i < R; i++) {
    solution();
  }
  return 0;
}
