#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 998244353;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
__attribute__((constructor)) void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}
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;
  }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint choose(int n, int a) {
  mint x = 1, y = 1;
  for (int i = 0; i < (a); i++) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}
vector<mint> dp(200010, 0), dpsum(200010, 0);
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(k);
  for (int i = 0; i < (k); i++) cin >> v[i].first >> v[i].second;
  dp[1] = 1;
  for (int i = (2); i < (n + 1); i++) {
    for (int j = 0; j < (k); j++) {
      int li = max(i - v[i].second - 1, 0);
      int ri = max(i - v[i].first, 0);
      dp[i] += dpsum[ri] - dpsum[li];
    }
    dpsum[i] += dp[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}
