#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// auto mod int
const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    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;
    }
    // for prime mod
    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; }
int n, k;

signed main() {
    cin >> n >> k;
    pint p[k];
    rep(i, 0, k) cin >> p[i].first >> p[i].second;
    sort(p, p + k);
    // rep(i, 0, k) { cout << p[i].first << " " << p[i].second << "\n"; }
    int dot[n] = {};
    rep(i, 0, n) {
        rep(j, 0, k) {
            if (p[j].first <= i && i <= p[j].second) dot[i]++;
        }
    }

    int dp[n] = {};
    rep(i, 0, n) {
        if (dot[i]) dp[i]++;
        rep(j, 0, i) {
            if (dot[j]) dp[i] = (dp[i] + dp[i - j]) % mod;
        }
    }
    // rep(i, 0, n) cout << dp[i] << "\n";
    cout << dp[n - 1] << "\n";
}