#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MOD = 998'244'353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<P> lr(k);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    lr.at(i) = make_pair(l, r);
  }
  set<int> s;
  rep(i, k) {
    P x = lr.at(i);
    for (int j = x.first; j <= x.second; j++) {
      s.insert(j);
    }
  }
  vector<ll> dp(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int ss : s) {
      if (i - ss > 0) {
        if (i - ss == 1) {
          dp.at(i) += 1;
        } else if (dp.at(i - ss) > 0) {
          dp.at(i) += dp.at(i - ss);
        }
      }
      dp.at(i) %= MOD;
    }
    dp.at(i) %= MOD;
  }
  cout << dp.at(n) << endl;
  return 0;
}
