#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, K;
  cin >> N >> K;
  long long ans = 0;
  vector<pair<int, int>> kukan;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    kukan.emplace_back(l, r);
  }
  sort(kukan.begin(), kukan.end());
  vector<long long> ruisekiwa(N + 1);
  ruisekiwa[0] = 0;
  ruisekiwa[1] = 1;
  for (int i = 2; i <= N; i++) {
    long long tmp = 0;
    for (auto p : kukan) {
      int l = p.first, r = p.second;
      if (i - l > 0) {
        if (i - r <= 0) {
          tmp += ruisekiwa[i - l];
        } else {
          tmp += (ruisekiwa[i - l] - ruisekiwa[i - r - 1]);
        }
        tmp %= MOD;
      }
    }
    ruisekiwa[i] = ruisekiwa[i - 1] + tmp;
    ruisekiwa[i] %= MOD;
  }
  cout << ruisekiwa[N] - ruisekiwa[N - 1] << endl;
}
