#include <bits/stdc++.h>
using namespace std;

template <typename container_type>
std::vector<std::vector<typename container_type::value_type>>
combWithReplace(container_type const &choices, size_t n) {
  using value_type = typename container_type::value_type;
  using selected_t = std::vector<value_type>;
  using itor_t = typename container_type::const_iterator;
  struct impl { // lambda で再帰は面倒なので クラスにする
    std::vector<std::vector<value_type>> &r_; // コピーを避けるために参照を持つ
    impl(std::vector<std::vector<value_type>> &r) : r_(r) {}
    void append(selected_t &s, itor_t b, itor_t e, size_t n) {
      if (n == 0) {
        r_.push_back(s);
      } else {
        for (auto it = b; it != e; ++it) {
          s.push_back(*it);
          append(s, it, e, n - 1);
          s.pop_back();
        }
      }
    };
  };
  std::vector<std::vector<value_type>> r;
  impl o{r};
  selected_t e;
  e.reserve(n);
  o.append(e, std::cbegin(choices), std::cend(choices), n);
  return r;
}

int main(void){
    int N ,K;
    cin >> N >> K;
    
    vector<int> S;
    int l, r;
    for (int i = 0; i < K; i++) {
        cin >> l >> r;
        int val = l;
        while (val <= r) {
            S.push_back(val);
            val++;
        }
    }
    
    long counter = 0;
    for (int i = 1; i < N; i++){
        vector<vector<int>> r = combWithReplace(S, i);
        unsigned long long len = r.size();
        
        for (int j = 0; j < len; j++){
            counter += (N - 1 == accumulate(r[j].begin(), r[j].end(), 0));
        }
        counter %= 998244353;   
    }
    cout << counter;

}
