#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = 1e16;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> L(m), R(m);
  for (long long i = 0; i < m; i++) {
    cin >> L[i] >> R[i];
    R[i]++;
  }
  vector<vector<long long>> dp(n + 10, vector<long long>(m + 1));
  dp[1][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < m; j++) {
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod;
      if (i + L[j] <= n) {
        dp[i + L[j]][j + 1] = (dp[i + L[j]][j + 1] + dp[i][j]) % mod;
      }
      if (i + R[j] <= n + 1) {
        dp[i + R[j]][j + 1] = (dp[i + R[j]][j + 1] + mod - dp[i][j]) % mod;
      }
    }
  }
  for (long long j = 1; j <= m; j++) {
    for (long long i = 1; i <= n - 1; i++) {
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
