#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const int64_t INF = 1e18;
const int inf = 1e9;
const int64_t mod = 998244353;
bool print_space_enable = false;
void print() {
  cout << '\n';
  print_space_enable = false;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  if (print_space_enable) std::cout << " ";
  cout << fixed << setprecision(15) << head;
  print_space_enable = true;
  print(std::forward<Tail>(tail)...);
}
template <typename T>
void print(vector<T> v) {
  for (size_t i = 0; i < v.size(); i++) {
    if (i > 0) std::cout << " ";
    std::cout << v[i];
  }
  std::cout << '\n';
}
int64_t dp[200002];
void solve() {
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> l(n), r(n);
  for (int64_t i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    r[i]++;
  }
  dp[0] = 1;
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < k; j++) {
      if (l[j] > i) continue;
      int64_t add = dp[i - l[j]];
      if (r[j] <= i) {
        add = (add - dp[i - r[j]] + mod) % mod;
      }
      dp[i] = (dp[i] + add) % mod;
    }
    dp[i] = (dp[i] + dp[i - 1]) % mod;
  }
  print(dp[n - 1] - dp[n - 2]);
}
int main() {
  solve();
  return 0;
}
