#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)998244353;
const int MAX = 1e6;
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
int arr[MAX], n, k;
long long int ans[MAX];
long long int dp[MAX];
long long int recur(int pos) {
  if (pos == n)
    return 1;
  else if (pos > n)
    return 0;
  long long int &ret = dp[pos];
  if (~ret) return ret;
  ret = 0;
  for (int i = 1; i + pos <= n; i++) {
    if (!arr[i]) continue;
    ret += recur(pos + i);
    ret %= MOD;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  while (k--) {
    int l, r;
    cin >> l >> r;
    arr[l]++;
    arr[r + 1]--;
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) arr[i] += arr[i - 1];
  cout << recur(1) << endl;
  return 0;
}
