#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int spf[MAXN];
long long fac1[MAXN], fac2[MAXN], inv[MAXN];
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++) spf[i] = i;
  for (int i = 4; i < MAXN; i += 2) spf[i] = 2;
  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i)
      for (int j = i * i; j < MAXN; j += i)
        if (spf[j] == j) spf[j] = i;
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
long long exp(long long n, long long m) {
  long long a = 1;
  while (m) {
    if (m & 1) a = (a * n % 998244353) % 998244353;
    m /= 2;
    n = (n * n) % 998244353;
  }
  return a;
}
void pre() {
  fac1[0] = fac2[0] = inv[1] = 1;
  for (int i = 1; i < MAXN; i++) {
    fac1[i] = (fac1[i - 1] * i) % 998244353;
    if (i > 1)
      inv[i] = (998244353 -
                ((long long)(998244353 / i) * inv[998244353 % i]) % 998244353) %
               998244353;
  }
  for (int i = 1; i < MAXN; i++) fac2[i] = (fac2[i - 1] * inv[i]) % 998244353;
}
long long C(int n, int k) {
  if (n < k) return 0;
  return ((fac1[n] * fac2[n - k] % 998244353) * fac2[k] % 998244353);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k, t = 1;
  while (t--) {
    cin >> n >> k;
    pair<long long, long long> inter[k];
    set<int> s;
    for (int i = 0; i < k; i++) {
      cin >> inter[i].first >> inter[i].second;
      for (int j = inter[i].first; j <= inter[i].second; j++) s.insert(j);
    }
    int dp[n + 1];
    dp[0] = 1;
    for (int i = 0; i < n; i++) dp[i + 1] = 0;
    for (int i = 1; i < n; i++) {
      for (auto x : s) {
        if (i - x < 0) break;
        dp[i] += dp[i - x];
        dp[i] %= 998244353;
      }
    }
    cout << dp[n - 1] << "\n";
  }
  return 0;
}
