#include <bits/stdc++.h>
using namespace std;
long long a[222222];
bool b[222222];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) b[j] = 1;
  }
  a[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      a[i] += b[j] * a[i - j];
      a[i] = a[i] % 998244353;
    }
  }
  cout << a[n - 1];
  return 0;
}
