#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const long long INF = -(long long)1e10;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > arr(k);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    arr[i] = {l, r};
  }
  vector<long long> dp(n + 2);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
    cout << i << " -- " << dp[i] << endl;
    for (int j = 0; j < k; j++) {
      if (i + arr[j].first > n) continue;
      int start = i + arr[j].first;
      int end = min(n, i + arr[j].second);
      dp[start] += dp[i];
      dp[start] %= mod;
      dp[end + 1] -= dp[i];
      dp[end + 1] %= mod;
    }
    dp[1] = 0;
  }
  if (dp[n] < 0) dp[n] += mod;
  cout << dp[n] << endl;
}
