#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll dv = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<P> v(k);
  for (ll i = 0; i < (ll)k; ++i) {
    cin >> v.at(i).first >> v.at(i).second;
  }
  sort(v.begin(), v.end());
  vector<ll> dp(n + 1);
  dp.at(1) = 1;
  for (ll i = 2; i <= n; ++i) {
    for (ll j = 0; j < (ll)k; ++j) {
      for (ll t = v.at(j).first; t <= v.at(j).second; ++t) {
        if ((i - t) < 1) {
          j = k;
          break;
        }
        dp.at(i) += dp.at(i - t);
        dp.at(i) %= dv;
      }
    }
  }
  cout << dp.at(n) << endl;
  return 0;
}
