#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<int, int>;
template <class T>
inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chmax(T& a, T b) {
  if (a < b) a = b;
}
const ll mod = 998244353;
int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<P> s(K);
  for (int i = 0; i < (K); i++) {
    std::cin >> s[i].first >> s[i].second;
  }
  std::sort(s.begin(), s.end());
  std::vector<ll> dp(N, 0);
  dp[0] = 1;
  int sz = s.size();
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < (K); j++) {
      int l = s[j].first;
      if (i + l > N - 1) break;
      int r = s[j].second;
      if (i + r > N - 1) {
        r = N - 1 - i;
      }
      for (int k = l; k <= r; k++) {
        if (i + k <= N - 1) {
          dp[i + k] += dp[i];
          dp[i + k] %= mod;
        }
      }
    }
  }
  std::cout << dp[N - 1] << std::endl;
  return 0;
}
