#include <bits/stdc++.h>
using namespace std;
int t, n, k, a, b;
vector<int> off;
long long dp[200001];
void printArray(int *, int);
long long solve(int idx) {
  if (idx == n - 1) return 1;
  if (dp[idx] != -1) return dp[idx];
  long long ans = 0;
  for (int i = 0; i < off.size(); i++)
    if (idx + off[i] < n) ans = (ans + solve(idx + off[i])) % 998244353;
  return dp[idx] = ans;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &a, &b);
    for (int j = a; j <= b; j++) off.push_back(j);
  }
  for (int i = 0; i < n; i++) dp[i] = -1;
  printf("%lld\n", solve(0));
  return 0;
}
void printArray(int *nums, int n) {
  for (int i = 0; i < n; i++) printf("%d ", nums[i]);
  printf("\n");
}
