#include <bits/stdc++.h>
using namespace std;
long long d[200001];
long long go(int n, vector<int> &s) {
  if (n <= 0) return 0;
  if (n == 1) return 1;
  if (d[n] != -1) return d[n];
  long long sum = 0;
  for (int step : s) {
    long long temp = go(n - step, s);
    sum += temp;
    sum %= 998244353;
  }
  d[n] = sum;
  return sum;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) s.push_back(j);
  }
  sort(s.begin(), s.end());
  memset(d, -1, 200000 * sizeof(long long));
  cout << go(n, s) << endl;
  return 0;
}
