#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll dv = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  set<ll> s;
  for (ll i = 0; i < (ll)k; ++i) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j <= r; ++j) s.insert(j);
  }
  vector<ll> dp(n + 1);
  dp.at(1) = 1;
  for (ll i = 2; i <= n; ++i) {
    for (auto p : s) {
      if ((i - p) < 1) break;
      dp.at(i) += dp.at(i - p);
      dp.at(i) %= dv;
    }
  }
  cout << dp.at(n) << endl;
  return 0;
}
