#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, K, L, R, mod = 998244353;
  cin >> N >> K;
  vector<pair<int, int>> LR;
  for (int i = 0; i < K; ++i) {
    cin >> L >> R;
    LR.push_back(make_pair(L, R));
  }
  vector<ll> dp(N, 0);
  dp[0] = 1;
  for (int i = 1; i < N; ++i) {
    for (auto& lr : LR) {
      for (int l = lr.first; l <= lr.second && l <= i; ++l) {
        dp[i] += dp[i - l];
        dp[i] %= mod;
      }
    }
  }
  cout << dp.back() % mod << endl;
  return 0;
}
