#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<long long, long long>> d(K);
  for (int i = 0; i < K; ++i) {
    cin >> d[i].first >> d[i].second;
  }
  vector<long long> dp(N, 0);
  dp[0] = 1;
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < K; ++j) {
      for (int k = d[j].first; k <= d[j].second && i - k >= 0; ++k) {
        dp[i] += dp[i - k];
        dp[i] %= 998244353LL;
      }
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
