#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> grid(2 * N + 10, 0);
  vector<long long> L(K), R(K);
  for (long long i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  grid[1] = 1;
  for (long long i = 1; i < N; i++) {
    for (long long j = 0; j < K; j++) {
      for (long long t = L[j]; t <= R[j]; t++) {
        grid[i + t] += grid[i] % 998244353;
        grid[i + t] %= 998244353;
      }
    }
  }
  cout << grid[N] % 998244353 << endl;
}
