#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD{998244353};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> segments;
  segments.reserve(K);
  for (int i{0}; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }
  sort(segments.begin(), segments.end());
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i{1}; i <= N; ++i) {
    for (auto s : segments) {
      if (s.first > N) {
        break;
      }
      for (ll j{s.first}; j <= s.second; j++) {
        if (i + j <= N) {
          dp[i + j] = dp[i + j] + dp[i] % MOD;
        } else {
          break;
        }
      }
    }
  }
  cout << (dp[N] % MOD) << endl;
  return EXIT_SUCCESS;
}
