#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long K;
  cin >> K;
  vector<vector<long long>> S;
  for (long i = 0; i < K; ++i) {
    long long L;
    cin >> L;
    long long R;
    cin >> R;
    vector<long long> lr;
    lr.emplace_back(L);
    lr.emplace_back(R);
    S.emplace_back(lr);
  }
  const auto slen = S.size();
  long long result = 0;
  map<long long, long long> currentTails;
  currentTails[1] = 1;
  while (currentTails.size() > 0) {
    map<long long, long long> previousTails = currentTails;
    currentTails.clear();
    for (auto it1 = previousTails.begin(); it1 != previousTails.end(); ++it1) {
      for (auto i = 0; i < slen; ++i) {
        long long updatedTailMin = it1->first + S[i][0];
        long long updatedTailMax = it1->first + S[i][1];
        if (updatedTailMin > N) {
        } else if (updatedTailMax < N) {
          for (auto j = updatedTailMin; j <= updatedTailMax; ++j) {
            if (currentTails.find(j) == currentTails.end()) {
              currentTails[j] = it1->second;
            } else {
              currentTails[j] += it1->second;
            }
          }
        } else {
          result += it1->second;
          result %= 998244353;
          for (auto j = updatedTailMin; j < N; ++j) {
            if (currentTails.find(j) == currentTails.end()) {
              currentTails[j] = it1->second;
            } else {
              currentTails[j] += it1->second;
            }
          }
        }
      }
    }
  }
  cout << result << endl;
}
