#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
struct mint {
  ll x;
  mint(ll 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 { 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(ll 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
vector<ll> dp;
vector<int> choices;
mint ways(int n) {
  if (dp[n] > -1) return dp[n];
  if (n == 1) return 1;
  if (n == 0) return 0;
  mint res = 0;
  for (int c : choices) {
    if (c > n) {
      break;
    }
    res += ways(n - c);
  }
  dp[n] = res.x;
  return dp[n];
}
int main() {
  int n, k;
  cin >> n >> k;
  dp = vector<ll>(n + 1, -1);
  for (int ri = 0; ri < (int)(k); ri++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      choices.push_back(i);
    }
  }
  sort(choices.begin(), choices.end());
  mint res = ways(n);
  cout << res << endl;
  return 0;
}
