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