#include <bits/stdc++.h>
const int MOD = 998244353;
int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> s(0);
  for (int i = 0; i < k; i++) {
    int l, r;
    std::cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    std::copy(s.begin(), s.end(), std::back_inserter(s));
  }
  int t = (int)s.size();
  std::vector<std::vector<int>> dp(t + 1, std::vector<int>(n));
  dp[0][0] = 1;
  for (int i = 0; i < t; ++i) {
    for (int j = 0; j <= n - 1; ++j) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j >= s[i]) {
        (dp[i + 1][j] += dp[i][j - s[i]]) %= MOD;
      }
    }
  }
  std::cout << dp[t][n - 1] << std::endl;
  return 0;
}
