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