#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int32_t main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n, 0);
  dp[0] = 1;
  vector<long long> ps(2, 0);
  ps[1] = 1;
  vector<long long> l(k), r(k);
  for (long long i = 0; i < k; ++i) {
    cin >> l[i] >> r[i];
  }
  for (long long i = 1; i < n; ++i) {
    for (long long j = 0; j < k; ++j) {
      long long lg, rg;
      if (i - l[j] < 0) continue;
      rg = max(0ll, i - l[j]);
      lg = max(0ll, i - r[j]);
      dp[i] += ps[rg + 1] - ps[lg];
    }
    ps.push_back((ps.back() + dp[i]) % mod);
    dp[i] %= mod;
  }
  cout << dp[n - 1];
}
