#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<int> v;
  for (long long int i = 0; i < k; i++) {
    long long int x, y;
    cin >> x >> y;
    for (long long int j = x; j <= y; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  vector<long long int> dp(n + 1, 0);
  dp[1] = 1;
  for (long long int i = 2; i <= n; i++) {
    long long int j = 0;
    while (j < v.size() && i - v[j] > 0) {
      dp[i] = (dp[i] % 998244353 + dp[i - v[j]] % 998244353) % 998244353;
      j++;
    }
  }
  cout << dp[n];
  return 0;
}
