#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> lr(k);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    lr[i] = {l, r};
  }
  vector<ll> dp(n);
  vector<ll> sdp(n + 1);
  dp[0] = 1;
  sdp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int left = max(0, i - lr[j].second);
      int right = max(0, i - lr[j].first + 1);
      dp[i] += (sdp[right] - sdp[left]) % MOD;
    }
    sdp[i + 1] = (sdp[i] + dp[i]) % MOD;
  }
  cout << dp[n - 1] << endl;
}
