#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using V = vector<long long>;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 998244353;
struct mint {
  long long x;
  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;
  }
};
map<long long, long long> sm;
mint dp[200005];
void solve_abc_d() {
  long long n, k;
  long long l_ans = 0;
  cin >> n >> k;
  long long l, r;
  for (long long i = 0; i < (long long)(k); i++) {
    cin >> l >> r;
    for (long long j = l; j < (long long)(r + 1); j++) {
      ++sm[j];
    }
  }
  long long d;
  for (long long i = 0; i < (long long)(n); i++) {
    dp[i] = 0;
  }
  dp[1] = 1;
  for (long long i = 1; i <= (long long)(n); i++) {
    for (auto itr = sm.begin(); itr != sm.end(); ++itr) {
      d = itr->first;
      if (i + d <= n) {
        dp[i + d] += dp[i];
      }
    }
  }
  cout << dp[n].x << "\n";
  return;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  cout << setprecision(15);
  solve_abc_d();
  return 0;
}
