#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long mod = 998244353;
  vector<int> A;
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) A.push_back(j);
  }
  sort(A.begin(), A.end());
  vector<long long> dp(n + 1, 0);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < A.size(); j++) {
      int ind = i - A[j];
      if (ind <= 0) break;
      dp[i] = (dp[i] % mod + dp[ind] % mod) % mod;
      if (dp[i] > mod) dp[i] = dp[i] % mod;
    }
  }
  cout << dp[n] % mod << endl;
  return 0;
}
