#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> slide;
  set<long long> T;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      T.insert(j);
    }
  }
  set<long long>::iterator it;
  for (it = T.begin(); it != T.end(); it++) slide.push_back(*it);
  vector<long long> dp(n, 0);
  dp[0] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < slide.size(); j++) {
      if (i - slide[j] >= 0) {
        dp[i] += dp[i - slide[j]];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
