#include <bits/stdc++.h>
using namespace std;
int l[200001], r[200001];
set<int> se;
vector<int> v;
long long dp[200001];
long long dpsum[200001];
int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  dp[1] = 1LL, dpsum[1] = 1LL;
  for (int i = 1; i <= 200000; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i] = (dp[i] + dpsum[max(0, i - l[j])] - dpsum[max(0, i - r[j] - 1)]) %
              (long long)998244353;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % (long long)998244353;
  }
  printf("%lld", dp[n]);
  return 0;
}
