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