#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 998244353;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;

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 {
        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(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 {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint per(int n, int k) {
        return fact[n]*ifact[n-k];
    }
};

    


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vector<P> p(k);
    
    rep(i, k) cin >> p[i].fi >> p[i].se;
    mint ans = 0;
    /*
    vector<int> nk(n+5);
    rep(i, k) {
        nk[p[i].fi]++;
        nk[p[i].se+1]--;
    }
    
    rep(i, n+5) {
        if (i==0) continue;
        nk[i] += nk[i-1];
    }
    vector<bool> ok(n+5);
    rep(i, n+5) {
        if (nk[i]>0) ok[i] = true;
        //debug(i);
        //debug(ok[i]);
    }
    */
    vector<mint> dp(n);
    vector<mint> sum(n);
    
    sum[0] = 0;
    dp[0] = 1;
    rep(i, n) {
        if (i>0) {
            sum[i] += sum[i-1];
            dp[i] = sum[i];
        }
        rep(j, k) {
            int l = i + p[j].fi;
            int r = i + p[j].se + 1;
            if (l<n) sum[l] += dp[i];
            if (r<n) sum[r] -= dp[i];
        }
        //debug(dp[i]);
        
    }
    /*
    for (int i=1; i<=n-1; i++) {
        for (int j=1; j<=10; j++) {
            if (!ok[j]) continue;
            if (i-j<0) continue;
            dp[i] += dp[i-j];
        }
    }
    */
    ans = dp[n-1];
    
    pr(ans);
    return 0;
}


Measured memory_bytes: 6348