#include <bits/stdc++.h>
using namespace std;
int fact(int n) {
  int ans = 1;
  while (n > 1) {
    ans *= n;
    n--;
  }
  return ans;
}
int comb(vector<int> Hist) {
  int size = Hist.size();
  int sum = 0;
  for (auto i : Hist) {
    sum += i;
  }
  int ans = fact(sum);
  for (auto i : Hist) {
    ans /= fact(i);
  }
  return ans;
}
int64_t ways(int N, vector<int> S) {
  int size = S.size();
  if (N == 1) {
    return 1;
  } else if (N < 1) {
    return 0;
  }
  int64_t temp = 0;
  for (int i = 0; i < size; i++) {
    temp += ways(N - S.at(i), S) % 998244353;
    temp %= 998244353;
  }
  return temp;
}
int64_t ways2(int N, vector<int> S, vector<int> Hist) {
  int size = S.size();
  if (N == 1) {
    return comb(Hist);
  } else if (N < 1) {
    return 0;
  }
  if (size < 1) {
    return 0;
  }
  int64_t temp = 0;
  int largest = S.at(size - 1);
  int p = (N - 1) / largest;
  for (int i = 0; i <= p; i++) {
    vector<int> Sdum = S;
    Sdum.pop_back();
    vector<int> Hdum = Hist;
    Hdum.push_back(i);
    temp += ways2(N - largest * i, Sdum, Hdum) % 998244353;
    temp %= 998244353;
  }
  return temp;
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  vector<int> S;
  for (int i = 0; i < K; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  for (int i = 0; i < K; i++) {
    int cursor = L.at(i);
    while (cursor <= R.at(i)) {
      S.push_back(cursor);
      cursor++;
    }
  }
  vector<int> Hist(0);
  int64_t ans = ways2(N, S, Hist);
  cout << ans << endl;
}
