#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 998244353;
using mint = Fp<MOD>;
const int MAX_N=1<<20;
ll N;
mint dat[2*MAX_N-1];
vector<mint> lazy;
void init(int n_){
    N=1;
    while(N<n_) N*=2;
    fill(dat,dat+2*N-1,0);
    lazy.resize(2*N-1,0);
}
void eval(int k,int l,int r) {
    if(lazy[k]!=0){
        dat[k]+=lazy[k];
        if(r-l>1){
            lazy[2*k+1]+=lazy[k]/2;
            lazy[2*k+2]+=lazy[k]/2;
        }
        lazy[k]=0;
    }
}
void add(int a,int b,mint x,int k=0,int l=0,int r=N){
    eval(k,l,r);
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
        lazy[k]+=x*(r-l);
        eval(k,l,r);
    }
    else{
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
        dat[k]=dat[2*k+1]+dat[2*k+2];
    }
}
mint sum(int a,int b,int k=0,int l=0,int r=N){
    if(r<=a||b<=l) return 0;
    eval(k,l,r);
    if(a<=l&&r<=b) return dat[k];
    mint vl=sum(a,b,2*k+1,l,(l+r)/2);
    mint vr=sum(a,b,2*k+2,(l+r)/2,r);
    return vl+vr;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int L[20],R[20];
    rep(i,k) cin>>L[i]>>R[i];
    init(n+1);
    add(1,2,1);
    rep1(i,n){
        mint a=sum(i,i+1);
        rep(j,k){
            if(i+L[j]<=n) add(i+L[j],min(n+1,i+R[j]+1),a);
        }
    }
    cout<<sum(n,n+1);
}

Measured memory_bytes: 11356