#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << fixed << setprecision(15);
  ;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> lr(k);
  for (long long i = 0, i_len = (long long)(k); i < i_len; i++)
    cin >> lr[i].first >> lr[i].second;
  sort(lr.begin(), lr.end());
  vector<long long> dp(n * 2 + 1, 0), sect(n * 2 + 1, 0);
  dp[1] = 1, sect[1] = 1;
  for (long long i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + sect[i];
    dp[i] %= 998244353;
    for (auto &range : lr) {
      sect[i + range.first] += dp[i];
      sect[i + range.first] %= 998244353;
      sect[i + range.second + 1] -= dp[i];
      sect[i + range.second + 1] %= 998244353;
    }
  }
  cout << sect[n] << "\n";
  return 0;
}
