#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long dp[200005];
long long stp[200005];
long long idx = 0;
signed main() {
  scanf("%lld%lld", &n, &k);
  register long long i, j;
  for (i = 1; i <= k; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    for (j = x; j <= y; ++j) stp[++idx] = j;
  }
  dp[1] = 1;
  for (i = 2; i <= n; ++i) {
    for (j = 1; j <= idx; ++j) {
      if (i - stp[j] >= 1) dp[i] = (dp[i] + dp[i - stp[j]]) % 998244353;
    }
  }
  printf("%lld\n", dp[n]);
  return 0;
}
