#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  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 j = l; j <= r; ++j) {
      s.push_back(j);
    }
  }
  int x = 998244353;
  std::vector<long> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int d : s) {
      int j = i + d;
      if (j > n) {
        continue;
      }
      dp[j] += dp[i];
    }
  }
  std::cout << dp[n] % x << std::endl;
  return 0;
}
