#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ai(k);
  vector<int> bi(k);
  for (int i = 0; i < k; ++i) {
    cin >> ai[i] >> bi[i];
  }
  vector<long long> ans(n, 0);
  ans[0] = 1;
  int p = 0;
  while (p < n) {
    for (int i = 0; i < k; ++i) {
      for (int j = p + ai[i]; j < min(n, p + bi[i] + 1); ++j) {
        ans[j] = (ans[j] + ans[p]) % 998244353;
      }
    }
    ++p;
  }
  cout << ans[n - 1] << endl;
  return 0;
}
