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