#include <bits/stdc++.h>
int main(void) {
  int n, k;
  int l[10], r[10];
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  int dp[n];
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i] = 0;
    for (int j = 0; j < k && l[j] < i + 1; j++) {
      for (int m = l[j]; m <= r[j] && m < i + 1; m++) {
        if (i == m) {
          dp[i]++;
        }
        dp[i] += dp[i - m];
        while (dp[i - m] > 998244353) {
          dp[i - m] -= 998244353;
        }
      }
    }
  }
  printf("%d", dp[n - 1]);
}
