#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<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 1; i < n; ++i) {
    for (auto& m : mv) {
      for (long long j = m.first; j <= m.second; ++j) {
        if (n < i + j) {
          break;
        }
        dp[i + j] = (dp[i + j] + dp[i]) % mod;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
