#include <bits/stdc++.h>
using ll = long long;
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<int> s;
  for (int i = 0; i < (K); i++) {
    int l, r;
    std::cin >> l >> r;
    for (int i = l; i <= r; i++) {
      s.push_back(i);
    }
  }
  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 < sz; j++) {
      int d = s[j];
      if (i + d <= N - 1) {
        dp[i + d] += dp[i];
        dp[i + d] %= mod;
      } else {
        break;
      }
    }
  }
  std::cout << dp[N - 1] << std::endl;
  return 0;
}
