#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long nn, kk, ll, rr;
  cin >> nn >> kk;
  vector<pair<long long, long long>> memo(kk);
  for (long long ii = 0; ii < kk; ii++) {
    cin >> memo[ii].first >> memo[ii].second;
  }
  vector<long long> vv(nn, 0), table(nn, 0);
  vv[0] = 1;
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    vv[(*ite).first] += vv[0];
    if ((*ite).second + 1 < nn) {
      vv[(*ite).second + 1] -= vv[0];
    }
  }
  for (long long ii = 1; ii < nn; ii++) {
    vv[ii] += table[ii - 1];
    if (vv[ii] < 0) {
      vv[ii] += mod;
    }
    vv[ii] %= mod;
    table[ii] = vv[ii];
    for (auto ite = memo.begin(); ite != memo.end(); ite++) {
      if (ii + (*ite).first < nn) {
        vv[ii + (*ite).first] += table[ii];
      }
      if (ii + (*ite).second + 1 < nn) {
        vv[ii + (*ite).second + 1] -= table[ii];
      }
    }
  }
  cout << table[nn - 1] << endl;
  return 0;
}
