#include <bits/stdc++.h>
using namespace std;
int const MOD = 998244353;
int dp[200005];
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> dist;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      dist.push_back(i);
    }
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (auto d : dist) {
      dp[i + d] = (dp[i + d] + dp[i]) % MOD;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
