#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, i, j, a, b;
  cin >> N >> K;
  vector<long long int> DP(N + 10, 0), P(0);
  for (i = 0; i < K; i++) {
    cin >> a >> b;
    for (j = a; j <= b; j++) {
      P.emplace_back(j);
    }
  }
  sort(P.begin(), P.end());
  a = P.size();
  DP[1] = 1;
  for (i = 1; i < N; i++) {
    if (DP[i] != 0) {
      for (j = 0; i + P[j] <= N && j < a; j++) {
        DP[i + P[j]] = (DP[i] + DP[i + P[j]]) % 998244353;
      }
    }
  }
  cout << DP[N] << endl;
}
