#include <bits/stdc++.h>
using namespace std;
int recursive_move(const int n, const vector<int>& vs, int count) {
  if (n == 0) {
    return count + 1;
  } else if (n < 0) {
    return count;
  }
  for (int x : vs) {
    count = recursive_move(n - x, vs, count);
  }
  return count;
}
int main() {
  char line[256];
  fgets(line, 255, stdin);
  int N, K;
  sscanf(line, "%d %d", &N, &K);
  vector<int> Ls, Rs;
  vector<int> vs;
  Ls.reserve(K);
  Rs.reserve(K);
  for (int i = 0; i < K; ++i) {
    fgets(line, 255, stdin);
    int l, r;
    sscanf(line, "%d %d", &l, &r);
    Ls.push_back(l);
    Rs.push_back(r);
    for (int j = l; j <= r; ++j) vs.push_back(j);
  }
  int count = recursive_move(N - 1, vs, 0);
  const int magic = 998244353;
  printf("%d\n", count % magic);
  return 0;
}
