#include <bits/stdc++.h>
using namespace std;
int N, K;
bool flg[200005];
int dp[400010] = {0, 1}, maxx;
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= K; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    for (int j = a; j <= b; j++) flg[j] = 1;
    if (b > maxx) maxx = b;
  }
  for (int i = 1; i <= N; i++) {
    if (dp[i] == 0) continue;
    for (int j = 1; j <= maxx; j++) {
      if (flg[j] == 0) continue;
      dp[i + j] += dp[i];
      dp[i + j] %= 998244353;
    }
  }
  printf("%d", dp[N]);
  return 0;
}
