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