#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 60);
const int MOD = 998244353;
long long dp[201010] = {0};
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> L(k), R(k);
  for (int i = 0; i < (int)k; i++) {
    cin >> L[i] >> R[i];
  }
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < n; i++) {
    if (i > 0) dp[i] += dp[i - 1];
    dp[i] %= MOD;
    for (int j = 0; j < (int)k; j++) {
      int l = L[j], r = R[j];
      if (i + l >= n) continue;
      dp[i + l] += dp[i];
      dp[i + l] %= MOD;
      if (i + r + 1 >= n || l == r) continue;
      dp[i + r + 1] -= dp[i];
      dp[i + r + 1] += MOD;
      dp[i + r + 1] %= MOD;
    }
  }
  cout << dp[n - 1] << endl;
}
