#include <bits/stdc++.h>
using namespace std;
int n, k;
int l[10], r[10], a[200001];
const int M = 998244353;
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  fill(a, a + n + 1, 0);
  a[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n) {
        for (int k = l[j]; k <= r[j]; k++) {
          if (i + k <= n) a[i + k] = (a[i + k] + a[i]) % M;
        }
      }
    }
  }
  cout << a[n] << endl;
}
