#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < (K); i++) {
    cin >> L[i] >> R[i];
  }
  long long ans = 0;
  long long M = 998244353;
  vector<long long> route(N + 1, 0);
  route[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int k = 0; k < K; k++) {
      for (int j = L[k]; j <= R[k]; j++) {
        if (i - j < 0) {
          break;
        }
        route[i] = (route[i] + route[i - j]) % M;
      }
    }
  }
  cout << route[N] << endl;
  return 0;
}
