#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T x) {
  std::cout << x << " ";
}
template <typename T>
void println(T x) {
  std::cout << x << "\n";
}
signed main(void) {
  long long n, k;
  cin >> n >> k;
  vector<long long> s;
  for (long long i = 0; i < (k); i++) {
    long long l, r;
    cin >> l >> r;
    for (long long i = (l); i < (r + 1); i++) s.push_back(i);
  }
  sort((s).begin(), (s).end());
  vector<long long> dp(n + 1, 0);
  for (long long i = 0; i < (s.size()); i++) {
    dp[s[i]] = 1;
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < (s.size()); j++) {
      if (i - s[j] >= 0) dp[i] += dp[i - s[j]];
      dp[i] %= 998244353;
    }
  }
  print(dp[n - 1]);
}
