#include <bits/stdc++.h>
using namespace std;
long long n;
long long k;
long long mod = 998244353;
vector<long long> v;
long long y;
long long dp[200005];
long long solve() {
  for (long long i = 1; i <= n; i++) {
    long long ans = 0;
    for (long long o = 0; o < y; o++) {
      if (i - v[o] < 0) break;
      ans += dp[i - v[o]];
    }
    dp[i] = ans % mod;
  }
  return dp[n - 1];
}
int main() {
  cin >> n >> k;
  dp[0] = 1;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  y = v.size();
  cout << solve() << endl;
  return 0;
}
