#include <bits/stdc++.h>
using namespace std;
long long L[11], R[11];
long long N, K;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % 998244353 + 998244353) % 998244353) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= 998244353) x -= 998244353;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += 998244353 - a.x) >= 998244353) x -= 998244353;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= 998244353;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(998244353 - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
bool visited[400010];
mint dp[400010];
mint calc(long long n = 1) {
  if (n > N) return dp[n] = 0;
  if (visited[n]) return dp[n];
  if (n == N) return dp[n] = 1;
  mint ret = 0;
  for (long long i = 0; i < K; i++) {
    for (long long j = L[i]; j <= R[i]; j++) ret += calc(n + j);
  }
  visited[n] = true;
  return dp[n] = ret;
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  for (long long i = 0; i < K; i++) cin >> L[i] >> R[i];
  for (long long i = 0; i < N + 1; i++) dp[i] = -1;
  dp[0] = 0;
  cout << calc().x << endl;
  return 0;
}
