#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int>> Kukan(K, vector<int>(2));
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> Kukan.at(i).at(j);
    }
  }
  vector<int> Hohaba(0);
  for (int i = 0; i < K; i++) {
    for (int j = Kukan.at(i).at(0); j <= Kukan.at(i).at(1); j++) {
      Hohaba.push_back(j);
    }
  }
  vector<int> Idou_W(N, 0);
  Idou_W.at(0) = 1;
  for (int n = 1; n < N; n++) {
    for (int d : Hohaba) {
      if (n >= d) {
        Idou_W.at(n) = (Idou_W.at(n) + Idou_W.at(n - d)) % 998244353;
      }
    }
  }
  cout << Idou_W.at(N - 1) << endl;
}
