#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ok[n + 1];
  long long way[n + 1];
  memset(ok, 0, sizeof(ok));
  memset(way, 0, sizeof(way));
  way[1] = 1;
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; ++j) ok[j] = 1;
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 1; i + j <= n; ++j) {
      way[i + j] = (way[i + j] + way[i] * ok[j]) % 998244353;
    }
  }
  way[n] = (way[n] + 998244353) % 998244353;
  cout << way[n] << "\n";
  return 0;
}
