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