#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  vector<int> masu;
  int mod = 998244353;
  masu.resize(N);
  int L, R;
  for (int i = 0; i < K; i++) {
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      S.push_back(j);
    }
  }
  int s_length = S.size();
  masu[0] = 1;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < s_length; j++) {
      if (i + S[j] < N) {
        masu[i + S[j]] = (masu[i + S[j]] + masu[i]) % mod;
      }
    }
  }
  cout << masu[N - 1] << endl;
  return 0;
}
