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