#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int, int> > D;
int main() {
  int N, K, i, j, k;
  ll mod = 998244353;
  cin >> N >> K;
  D = vector<pair<int, int> >(K);
  int l, r;
  for (i = 0; i < K; i++) {
    cin >> l >> r;
    D[i] = make_pair(l, r);
  }
  vector<ll> dp(N, 0);
  dp[0] = 1;
  for (i = 1; i < N; i++) {
    for (j = 0; j < D.size(); j++) {
      for (k = D[j].first; k <= D[j].second && k <= i; k++) {
        dp[i] += dp[i - k];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
