#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k, jc[200010], dp[200010], tot;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1, l, r; i <= k; i++) {
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) jc[++tot] = j;
  }
  sort(jc + 1, jc + tot + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= tot; j++) {
      if (i - jc[j] < 1) break;
      dp[i] = (dp[i] + dp[i - jc[j]]) % mod;
    }
  printf("%d\n", dp[n]);
}
