#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
const long long mod = 998244353;
long long a[N * 2];
bool d[N];
long long dp[N];
int main() {
  int n, k, cnt = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) {
      if (!d[j]) {
        a[cnt++] = j;
        d[j] = 1;
      }
    }
  }
  cnt--;
  sort(a, a + cnt);
  dp[1] = 1;
  for (int j = 2; j <= n; j++) {
    for (int i = 0; i <= cnt; i++) {
      if (j - a[i] > 0) {
        dp[j] = (dp[j] + dp[j - a[i]]) % mod;
      }
    }
  }
  printf("%lld\n", dp[n]);
  return 0;
}
