#include <bits/stdc++.h>
using namespace std;
int countways(int N, int s[], int m) {
  int dp[N + 1];
  dp[1] = 1;
  for (int step = 2; step <= N; step++) {
    dp[step] = 0;
    for (int j = 0; j < m; j++)
      if (s[j] < step)
        dp[step] =
            (dp[step] % 998244353 + dp[step - s[j]] % 998244353) % 998244353;
  }
  return dp[N];
}
int main() {
  int N;
  int K;
  cin >> N >> K;
  int arr[K][2];
  int S[N];
  for (int i = 0; i < K; i++) cin >> arr[i][0] >> arr[i][1];
  int m = 0;
  for (int i = 0; i < K; i++)
    for (int j = arr[i][0]; j <= arr[i][1]; j++) S[m++] = j;
  int ans = countways(N, S, m);
  cout << ans << endl;
}
