#include <bits/stdc++.h>
template <typename T>
T GCD(T a, T b) {
  return a ? GCD(b % a, a) : b;
}
template <typename T>
T LCM(T a, T b) {
  return (a * b) / GCD(a, b);
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
  for (auto ob : v) os << ob << " ";
  return os;
}
template <typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
  for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
  return os;
}
using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;
class DLeapingTak {
  vector<pair<int, int>> range;
  int Ways(int target) {
    int dp[target + 1];
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    for (int i = 1; i <= target; i++) {
      for (auto k : range) {
        for (int j = k.first; j < k.second + 1; ++j) {
          if (i >= j) {
            dp[i] += (dp[i - j] % 998244353);
            dp[i] %= 998244353;
          }
        }
      }
    }
    return dp[target];
  }

 public:
  void solve(std::istream &in, std::ostream &out) {
    int n, k;
    in >> n >> k;
    for (int i = 0; i < k; ++i) {
      int l, r;
      in >> l >> r;
      range.push_back({l, r});
    }
    out << Ways(n - 1) << endl;
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  DLeapingTak solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
