#include <bits/stdc++.h>
using namespace std;
int read() {
  char x = getchar();
  int u = 0, fg = 0;
  while (!isdigit(x)) {
    if (x == '-') fg = 1;
    x = getchar();
  }
  while (isdigit(x)) {
    u = (u << 3) + (u << 1) + (x ^ 48);
    x = getchar();
  }
  return fg ? -u : u;
}
const int maxx = 2e5 + 10, mod = 998244353;
long long dp[maxx], sum[maxx];
int n, k;
struct node {
  int l, r;
} q[maxx];
int main() {
  n = read();
  k = read();
  for (int i = (1); i <= (k); ++i) {
    q[i].l = read();
    q[i].r = read();
  }
  for (int i = (0); i <= (n); ++i) dp[i] = sum[i] = 0;
  dp[1] = sum[1] = 1;
  for (int i = (2); i <= (n); ++i) {
    for (int j = (1); j <= (k); ++j) {
      int l = i - q[j].r, r = i - q[j].l;
      l = max(l, 1);
      long long tmp = (sum[r] - sum[l - 1] + mod) % mod;
      dp[i] = (dp[i] + tmp) % mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  printf("%lld\n", dp[n]);
  return 0;
}
