#include <bits/stdc++.h>
using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;
LLONG dp[200001];
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> lrs(K);
  for (int i = 0; i < K; ++i) {
    cin >> lrs[i].first >> lrs[i].second;
  }
  dp[1] = 1;
  for (int i = 1; i <= N; ++i) {
    if (dp[i] == 0) continue;
    for (const auto& lr : lrs) {
      for (int d = lr.first; d <= lr.second && i + d <= N; ++d) {
        dp[i + d] += dp[i];
        dp[i + d] %= MOD;
      }
    }
  }
  cout << dp[N] << endl;
}
