#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(N, 1001001);
  vector<int> R(N, 1001001);
  for (int i = 0; i < (K); ++i) cin >> L[i] >> R[i];
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  vector<long long> num(N + 1, 0);
  num[1] = 1;
  int flag = 0;
  for (int i = 2; i <= N; i++) {
    flag = 0;
    for (int j = 0; j < K; j++) {
      for (int k = L[j]; k <= R[j]; k++) {
        if (i - k < 0) {
          flag = 1;
          break;
        }
        num[i] = (num[i] + num[i - k]) % 998244353;
      }
      if (flag == 1) {
        break;
      }
    }
  }
  cout << num[N] << endl;
  return 0;
}
