#include <bits/stdc++.h>
constexpr int mod = 998244353;
int calc(int n, const std::vector<int>& s, std::vector<int>& dp) {
  int result = 0;
  for (auto d : s) {
    if (n - d <= 0) break;
    if (dp[n - d] < 0) {
      dp[n - d] = calc(n - d, s, dp);
    }
    result += dp[n - d];
    result %= mod;
  }
  dp[n] = result;
  return result;
}
int solve(int n, int k, std::vector<int>& s) {
  sort(s.begin(), s.end());
  std::vector<int> dp(n + 1, -1);
  dp[1] = 1;
  return calc(n, s, dp);
}
int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> s;
  for (int i = 0; i < k; ++i) {
    int left, right;
    std::cin >> left >> right;
    for (int j = left; j <= right; ++j) {
      s.push_back(j);
    }
  }
  std::cout << std::setprecision(20);
  std::cout << solve(n, k, s) << std::endl;
}
