#include <bits/stdc++.h>
using namespace std;
int position(int now, set<int> num, int N, int* count) {
  if (now <= N) {
    for (auto i : num) {
      int tmp = position(now + i, num, N, count);
      if (tmp == N) *count += 1;
      *count %= 998244353;
      ;
    }
    return now;
  } else {
    return now;
  }
}
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  int count = 0;
  set<int> num;
  for (int i = 1; i <= K; i++) {
    int L, R;
    cin >> L >> R;
    for (int k = L; k <= R; k++) {
      num.insert(k);
    }
  }
  int now = 1;
  position(now, num, N, &count);
  ans = count % 998244353;
  ;
  cout << ans << endl;
  return 0;
}
