#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> ablestep;
  vector<int> HEX(N + 5, 0);
  while (K--) {
    int a, b;
    cin >> a >> b;
    for (; a <= b; a++) ablestep.push_back(a);
  }
  sort(ablestep.begin(), ablestep.end());
  HEX[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto s : ablestep) {
      if (s >= i) break;
      HEX[i] += HEX[i - s];
      HEX[i] %= 998244353;
    }
  }
  cout << HEX[N] << '\n';
}
