#include <bits/stdc++.h>
using namespace std;
long long d[200000];
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());
  d[1] = 1;
  for (int i = 2; i <= n; i++) {
    long long sum = 0;
    for (int step : s) {
      if (i - step <= 0) break;
      sum += d[i - step] % 998244353;
    }
    d[i] = sum % 998244353;
  }
  cout << d[n] << endl;
  return 0;
}
