#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int dp[N] = {};
int sum[N] = {};
int L[20] = {}, R[20] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> L[i] >> R[i];
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      dp[i] = (dp[i] + sum[max(0, i - L[j])] - sum[max(1, i - R[j]) - 1]) % mod;
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  dp[n] %= mod;
  if (dp[n] < 0) dp[n] += mod;
  cout << dp[n] << '\n';
  return 0;
}
