#include <bits/stdc++.h>
using namespace std;
int main() {
  const long long mod = 998244353;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> sv(k);
  for (auto& i : sv) {
    cin >> i.first >> i.second;
  }
  sort(sv.begin(), sv.end());
  vector<pair<long long, long long>> mv;
  mv.push_back(sv[0]);
  for (long long i = 1; i < k; ++i) {
    if (mv.back().second < sv[i].first) {
      mv.push_back(sv[i]);
    } else {
      mv.back().second = max(mv.back().second, sv[i].second);
    }
  }
  vector<pair<pair<long long, long long>, long long>> test;
  for (long long i = 1; i <= n; ++i) {
    long long dp = 0;
    if (i == 1) {
      dp = 1;
    }
    auto itr = test.begin();
    while (itr != test.end()) {
      if (itr->first.first <= i && i <= itr->first.second) {
        dp = (dp + itr->second) % mod;
      } else if (itr->first.second < i) {
        itr = test.erase(itr);
        continue;
      }
      ++itr;
    }
    if (i == n) {
      cout << dp << endl;
    }
    for (auto& m : mv) {
      long long l = i + m.first;
      long long r = min(n, i + m.second);
      if (l <= r) {
        test.push_back({{l, r}, dp});
      }
    }
  }
  return 0;
}
