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