#include <bits/stdc++.h>
using namespace std;
long long re[200001];
long long start(int s, int e, vector<int> v) {
  if (s > e) return 0;
  if (re[s] >= 0) return re[s];
  if (s == e) return 1;
  long long sum = 0;
  for (int i = 0; i < v.size(); i++) {
    sum = (sum + start(s + v[i], e, v)) % 998244353;
  }
  re[s] = sum;
  return sum;
}
int main() {
  for (long long i = 0; i < 200001; i++) re[i] = -1;
  int n, k;
  cin >> n >> k;
  int a[k][2];
  vector<int> v;
  for (int i = 0; i < k; i++) {
    cin >> a[i][0] >> a[i][1];
    for (int j = a[i][0]; j <= a[i][1]; j++) v.push_back(j);
  }
  cout << start(1, n, v) << "\n";
  return 0;
}
