#include <bits/stdc++.h>
using namespace std;
int t, n, k, a, b;
vector<pair<int, int>> off;
long long dp[200001], suffDP[200001 + 1];
void printArray(int *, int);
long long sum(int idx, int l, int r) {
  if (r == n - 1) return suffDP[l];
  return (suffDP[idx + l] - suffDP[idx + r + 1] + 998244353) % 998244353;
}
long long solve(int idx) {
  if (idx == n - 1) return 1;
  long long ans = 0;
  int first = 0;
  for (int i = 0; i < k && !first; i++) {
    if (off[i].second + idx < n)
      ans = (ans + sum(idx, off[i].first, off[i].second)) % 998244353;
    else if (off[i].first + idx >= n)
      first = 1;
    else {
      ans = (ans + sum(idx, off[i].first, n - 1)) % 998244353;
      first = 1;
    }
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &a, &b);
    off.push_back({a, b});
  }
  sort(off.begin(), off.end());
  suffDP[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    dp[i] = solve(i);
    suffDP[i] = (dp[i] + suffDP[i + 1]) % 998244353;
  }
  printf("%lld\n", dp[0]);
  return 0;
}
void printArray(int *nums, int n) {
  for (int i = 0; i < n; i++) printf("%d ", nums[i]);
  printf("\n");
}
