#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, kLen = 0;
  cin >> n >> kLen;
  vector<long long> board(n);
  vector<int> k;
  board[0] = 1;
  for (int i = 0; i < kLen; i++) {
    int x, y;
    cin >> x >> y;
    for (int i2 = x; i2 <= y; i2++) {
      k.push_back(i2);
    }
  }
  sort(k.begin(), k.end());
  for (int i = 0; i < n; i++) {
    long long board_i = board.at(i);
    for (int i2 = 0; i2 < k.size(); i2++) {
      int s = k.at(i2);
      if (i + s >= n) break;
      board.at(i + s) += board_i;
    }
  }
  cout << (board.at(n - 1) % 998244353);
}
