#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 2e5 + 10;
set<long long> Set;
long long dp[N];
signed main() {
  long long n, k;
  cin >> n >> k;
  while (k--) {
    long long l, r;
    cin >> l >> r;
    for (long long i = l; i <= r; i++) Set.insert(i);
  }
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    set<long long>::iterator it = Set.begin();
    for (; it != Set.end(); ++it) {
      if (i - *it >= 1) dp[i] += dp[i - *it];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
