#include <bits/stdc++.h>
using namespace std;
const long long INF = INT_MAX / 4;
const long long MOD = 998244353;
const double EPS = 1e-14;
const bool DEBUG = false;
const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";
template <class T>
void debug(T head) {
  if (DEBUG) {
    cout << head << endl;
  }
}
template <class Head, class... Body>
void debug(Head head, Body... body) {
  if (DEBUG) {
    cout << head << " ";
    debug(body...);
  }
}
void answer() {
  long N, K;
  cin >> N >> K;
  vector<long> L(K), R(K);
  vector<long> hops;
  vector<unsigned long long> dp(N, 0);
  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
    for (int j = L[i]; j <= R[i]; ++j) {
      hops.push_back(j);
    }
  }
  dp[0] = 1;
  long len = hops.size();
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < len; ++j) {
      if (i - hops[j] >= 0) {
        dp[i] += dp[i - hops[j]];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[N - 1] << endl;
  return;
}
int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.precision(16);
  answer();
  return 0;
}
