#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFL = 1e17;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k + 1), r(k + 1);
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<long long> dp(n + 1);
  vector<long long> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      int lim_r = i - l[j];
      int lim_l = i - r[j];
      dp[i] = (dp[i] + dpsum[lim_r] - dpsum[lim_l - 1]) % MOD;
    }
    dpsum[i] = (dp[i] + dp[i - 1]) % MOD;
  }
  cout << dp[n] << endl;
  return 0;
}
