#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t i, j, k, n;
  cin >> n >> k;
  set<int64_t> s;
  for (i = 1; i <= k; ++i) {
    int64_t x1, x2;
    cin >> x1 >> x2;
    for (j = x1; j <= x2; ++j) s.insert(j);
  }
  vector<int64_t> dp(n, 0);
  dp[0] = 1;
  for (i = 1; i < n; ++i) {
    for (auto it = s.begin(); it != s.end(); ++it)
      if (i - (*it) >= 0) dp[i] = (dp[i] + dp[i - (*it)]) % 998244353;
  }
  cout << dp[n - 1] % 998244353 << "\n";
  return 0;
}
