#include <bits/stdc++.h>
using namespace std;
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T> >& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
template <typename T, typename U>
void view(const std::map<T, U>& m) {
  for (const auto& e : m) {
    std::cout << e.first << "=>" << e.second << " ";
  }
  std::cout << std::endl;
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (long long i = 0; i < (long long)(K); i++) {
    cin >> L[i] >> R[i];
  }
  map<int, long long> m;
  m[1] = 1;
  for (long long i = 2; i < (long long)(N + 1); i++) {
    m[i] = 0;
    for (long long j = 0; j < (long long)(K); j++) {
      for (long long k = L[j]; k < (long long)(R[j] + 1); k++) {
        m[i] = (m[i] + m[i - k]) % 998244353;
      }
    }
  }
  cout << m[N] << endl;
  return 0;
}
