#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l, r, n, mod = 998244353, k;
  cin >> n >> k;
  vector<long long> a;
  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[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int j = 0; j < a.size(); j++) {
      if (i - a[j] > 0) dp[i] = (dp[i] + dp[i - a[j]]) % mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
