#include <bits/stdc++.h>
using namespace std;
long long mo = 1e9 + 7;
template <class T, class S>
void cmin(T& a, const S& b) {
  if (a > b) a = b;
}
template <class T, class S>
void cmax(T& a, const S& b) {
  if (a < b) a = b;
}
template <class A>
void PR(A a, long long n) {
  for (int i = 0; i < n; i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << "\n";
}
long double PI = 3.14159265358979323846;
const int mod = 998244353;
class mint {
  long long x;

 public:
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= 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(mod - 2); }
  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};
int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> L(K), R(K), S(N + 1);
  vector<mint> dp(N + 1);
  dp[1] = mint(1);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
    R[i]++;
  }
  PR(dp, N + 1);
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < K; i++) {
      for (long long j = (long long)(L[i]); j < (long long)(R[i]); j++) {
        if (N - j < 0) continue;
        dp[N] += dp[N - j];
      }
    }
  }
  cout << dp[N] << endl;
}
