#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const ll inf = 1000000000000;
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;
  }
};
int main() {
  ll n, k;
  cin >> n >> k;
  vector<mint> v(n + 100001, 0), vv(n + 100001, 0);
  v[0] = 1;
  Vi vl(k), vr(k);
  for (int i = 0; i < (int)(k); i++) cin >> vl[i] >> vr[i];
  for (int i = 0; i < (int)(n); i++) {
    if (i != 0) v[i] = v[i - 1].x + vv[i].x;
    for (int j = 0; j < (int)(k); j++) {
      int x = vl[j];
      int y = vr[j] + 1;
      vv[i + x] += v[i];
      vv[i + y] -= v[i];
    }
  }
  cout << vv[n - 1].x << endl;
}
