#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < (k); i++) cin >> l[i] >> r[i];
  vector<ll> dp(n + 1);
  dp[1] = 1;
  vector<ll> dpsum(n + 1);
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (k); j++) {
      int li = i - r[j];
      li = max(li, 1);
      int ri = i - l[j];
      if (ri < 0) continue;
      dp[i] += (dpsum[ri] - dpsum[li - 1]) % mod;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % mod;
  }
  cout << dp[n] << endl;
}
