#include <bits/stdc++.h>
using namespace std;
int n, K;
long long Ans[1000000 + 10];
int l[233], r[233];
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= K; i++) scanf("%d%d", &l[i], &r[i]);
  Ans[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= K; j++) {
      if (i < l[j]) continue;
      if (i >= r[j])
        Ans[i] = (Ans[i] + (Ans[i - l[j]] - Ans[i - r[j] - 1] + 998244353)) %
                 998244353;
      else
        Ans[i] = (Ans[i] + Ans[i - l[j]]) % 998244353;
    }
    Ans[i] = (Ans[i] + Ans[i - 1]) % 998244353;
  }
  cout << Ans[n] - Ans[n - 1];
  return 0;
}
