#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
static long long INF = (1LL << 62);
const long long C = 998244353;
long long N, K;
long long dp[200004] = {0};
int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  vector<long long> D;
  for (int i = 0; i < K; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      D.push_back(j);
    }
  }
  sort(D.begin(), D.end());
  dp[1] = 1;
  if (D[0] == 1) {
    dp[2] = 1;
  } else {
    dp[2] = 0;
  }
  for (int i = 3; i <= N; i++) {
    for (int j = 0; j < D.size() && i - D[j] >= 1; j++) {
      dp[i] += dp[i - D[j]];
      dp[i] %= C;
    }
    dp[i] %= C;
  }
  printf("%lld\n", dp[N]);
  return 0;
}
