#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  long long l, r;
  long long m = 998244353;
  std::cin >> N >> K;
  vector<long long> kumiawase(N, 0);
  kumiawase[0] = 1;
  vector<long long> list(0);
  for (int i = 0; i < K; i++) {
    std::cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      list.push_back(j);
    }
  }
  for (long long i = 1; i < N; i++) {
    for (long long j = 0; j < list.size(); j++) {
      if (i - list[j] >= 0) {
        kumiawase[i] = kumiawase[i] + kumiawase[i - list[j]];
        kumiawase[i] = kumiawase[i] % m;
      }
    }
  }
  std::cout << kumiawase[N - 1];
}
