#include <bits/stdc++.h>
using namespace std;
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template <class T>
inline bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void execute();
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  execute();
  return 0;
}
void execute() {
  long long dp0[200001] = {};
  long long dp1[200001] = {};
  dp0[0] = 1;
  long long N, K;
  cin >> N >> K;
  vector<pair<int, int> > areas(K);
  long long n = 0;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    areas[i] = make_pair(l, r);
  }
  sort(areas.begin(), areas.end());
  long long *dp_r = dp0;
  long long *dp_w = dp1;
  for (int i = 1; i < N; i++) {
    dp_w[i - 1] = dp_r[i - 1];
    for (int k = 0; k < K; k++) {
      int r = i - areas[k].first;
      int l = i - areas[k].second;
      if (r < 0) continue;
      if (l < 0) l = 0;
      for (int j = l; j <= r; j++) {
        dp_w[i] += dp_r[j];
        dp_w[i] %= 998244353;
      }
    }
    long long *t = dp_r;
    dp_r = dp_w;
    dp_w = t;
  }
  n %= 998244353;
  cout << dp_r[N - 1] << "\n";
}
