#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5, maxK = 10;
int n, k;
pair<int, int> lr[maxK];
vector<int> s;
const long long int mod = 998244353;
long long int memo[maxN];
long long int solve(int i = 1) {
  if (i >= n) return i == n;
  if (memo[i] != -1) return memo[i];
  long long int ans = 0;
  int pos = lower_bound(s.begin(), s.end(), n - i) - s.begin();
  if (pos == s.size()) pos--;
  for (int j = pos; j >= 0; j--) ans = (ans + solve(i + s[j])) % mod;
  return memo[i] = ans;
}
int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    s.clear();
    for (int i = 0; i < k; i++) {
      scanf("%d %d", &lr[i].first, &lr[i].second);
      for (int j = 0, end = lr[i].second - lr[i].first + 1; j < end; j++)
        s.push_back(lr[i].first + j);
    }
    sort(s.begin(), s.end(), less<int>());
    memset(memo, -1, sizeof(memo));
    long long int ans = solve();
    printf("%lld\n", ans);
  }
  return 0;
}
