#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s(0);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) s.push_back(j);
  }
  int si = s.size();
  vector<long long> a(n);
  a[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < si; j++) {
      int p = s[j];
      if (i + p < n) a[i + p] = (a[i + p] + a[i]) % 998244353;
    }
  }
  cout << a[n - 1] << endl;
}
