#include <bits/stdc++.h>
using namespace std;
void IO() {}
int ar[200005];
char ch[200005];
int m, n, k, ii;
int mark[200005];
long long dp[200005];
vector<int> v;
long long func(int val) {
  if (val == n) return 1;
  long long &re = dp[val];
  if (re != -1) return re;
  re = 0;
  for (int u : v) {
    if (val + u > n) break;
    re = (re + func(val + u)) % 998244353;
  }
  return re;
}
void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) mark[j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (mark[i]) v.push_back(i);
    dp[i] = -1;
  }
  printf("%lld\n", func(1));
}
int main() {
  IO();
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
