#include <bits/stdc++.h>
using namespace std;
const long long int mex = 2 * (1e5) + 5, p = 998244353;
long long int n, dp[mex], m[mex], k, x, y;
long long int func(long long int i) {
  if (i > n) return 0;
  if (dp[i] != -1) return dp[i];
  if (i == n) return 1;
  dp[i] = 0;
  for (long long int j = 1; j < n; j++)
    if (m[j] != 0) dp[i] = (dp[i] + func(i + j)) % p;
  return dp[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (long long int i = 0; i < mex; i++) {
    m[i] = 0;
    dp[i] = -1;
  }
  cin >> n >> k;
  while (k--) {
    cin >> x >> y;
    for (long long int i = x; i <= y; i++) m[i] = 1;
  }
  cout << func(1);
}
