#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long K;
  cin >> K;
  vector<long long> S;
  for (long i = 0; i < K; ++i) {
    long long L;
    cin >> L;
    long long R;
    cin >> R;
    for (long j = L; j <= R; ++j) {
      S.emplace_back(j);
    }
  }
  sort(S.begin(), S.end());
  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 updatedTail = it1->first + S[i];
        if (updatedTail == N) {
          result += it1->second;
          result %= 998244353;
          break;
        } else if (updatedTail > N) {
          break;
        } else {
          if (currentTails.find(updatedTail) == currentTails.end()) {
            currentTails[updatedTail] = it1->second;
          } else {
            currentTails[updatedTail] += it1->second;
          }
        }
      }
    }
  }
  cout << result << endl;
}
