#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k;
int main() {
  scanf("%d %d", &n, &k);
  vector<pair<int, int>> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    s.push_back({l, r});
  }
  vector<int> cnt(n + 1, 0);
  vector<int> preSum(n + 1, 0);
  cnt[1] = 1;
  preSum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      int l = i - s[j].second;
      int r = i - s[j].first;
      if (r < 0) continue;
      l = max(1, l);
      cnt[i] += preSum[r] - preSum[l - 1];
      cnt[i] %= mod;
    }
    preSum[i] = preSum[i - 1] + cnt[i];
    preSum[i] %= mod;
  }
  printf("%d\n", cnt[n]);
  return 0;
}
