#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  int N, K;
  cin >> N >> K;
  int L, R;
  vector<int> S;
  for (int i = 0; i < K; i++) {
    cin >> L >> R;
    for (int j = L; j <= R; ++j) {
      S.push_back(j);
    }
  }
  sort(S.begin(), S.end());
  int length = S.size();
  int *solutions = new int[N];
  for (int i = 0; i < N; ++i) {
    solutions[i] = 0;
  }
  solutions[0] = 1;
  for (int i = 0; i < N; ++i) {
    int s = solutions[i];
    for (int j = 0; j < length; ++j) {
      int k = i + S[j];
      if (k >= N) {
        break;
      }
      solutions[k] += s;
      if (solutions[k] > mod) {
        solutions[k] %= mod;
      }
    }
  }
  cout << solutions[N - 1] % mod;
  return 0;
}
