#include<bits/stdc++.h>
#define ll long long
#define print(ds) for(auto i:ds){cout<<i<<" ";} cout<<endl;
#define pp pair <ll, ll>
#define mod 1000000007
#define mod2 998244353
using namespace std;
vector <ll> tree (800020, 0);
vector <ll> lazy (800020, 0);
void update(int node, int start, int end, int index, ll value){
    if(start==end){
        tree[node] = value;
        return;
    }
    int mid = (start+end)/2;
    if(start<=index && index<= mid){
        update(node*2+1,start, mid,index, value);
    }
    else{
        update(node*2+2,mid+1, end, index, value);
    }
    tree[node] = (tree[node*2+1]+tree[node*2+2]);
    return ;
}

ll query(int node, int start, int end, int l, int r){
    if(r<start || l>end){
        return 0;
    }
    if(l<=start &&  end<=r){
        return tree[node];
    }
    else{
        int mid = (start+end)/2;
        return query(2*node+1, start, mid, l, r) + query(2*node+2, mid+1, end, l, r);
    }
}

void updateLazy(int node, ll start, ll end, ll l, ll r, ll value){    
    if(lazy[node]!=0){
        tree[node] = (tree[node]+((end-start+1)*lazy[node])%mod2)%mod2;
        if(start!=end){
            lazy[2*node+1] += lazy[node];
            lazy[2*node+1] %= mod2;
            lazy[2*node+2] += lazy[node];
            lazy[2*node+2] %= mod2;
        }
        lazy[node] = 0;
    }
    if(start >end || l>end || r<start){
        return ;
    }
    if(l<=start && end<=r){        
        tree[node] += (end-start+1)*value;
        if(start!=end){
            lazy[2*node+1] += value;
            lazy[2*node+2] += value;
            lazy[2*node+1]%=mod2;
            lazy[2*node+2]%=mod2;
        }
        return;
    }
    else{
        ll mid = (start+end)/2;
        updateLazy(node*2+1, start, mid, l, r, value);
        updateLazy(node*2+2, mid+1, end, l, r, value);
        tree[node] = tree[2*node+1]+tree[2*node+2];
        tree[node]%=mod2;
        return;
    }
}

ll queryLazy(int node, ll start, ll end , ll l, ll r){
    if(start >end  || l>end || r<start){
        return 0;
    }    
    if(lazy[node]!=0){
        tree[node] += ((end-start+1)*lazy[node])%mod2;
        tree[node]%=mod2;
        if(start!=end){
            lazy[2*node+1] += lazy[node];
            lazy[2*node+2] += lazy[node];
            lazy[2*node+1] %=mod2 ;
            lazy[2*node+2] %=mod2 ;
        }
        lazy[node] = 0;
    }
    if(l<=start && end<=r){
        return tree[node];
    }
    else{
        ll mid = (start+end)/2;
        return (queryLazy(node*2+1, start, mid, l, r)+queryLazy(node*2+2, mid+1, end, l, r))%mod2;
    }    
}

int main(){
    ll n, k;
    cin>>n>>k;
    updateLazy(0,0,n-1,0,0,1);
    vector <pp> v(k);
    for(int i=0; i<k; i++){
        ll a, b;cin>>a>>b;
        v[i] = make_pair(a-1,b-1);
    }
    vector <int> val(n,0);
    val[0]=1;
    for(int i=0; i<(n-1);i++){
        val[i] = queryLazy(0,0,n-1,i,i);
        for(int j=0; j<k; j++){
            if((v[j].first+i+1)>=n) continue;
            else if((v[j].second+i+1)>=n){
                updateLazy(0,0,n-1,v[j].first+i+1,n-1, val[i]); 
            }
            else {  
                updateLazy(0,0,n-1,v[j].first+i+1,v[j].second+i+1, val[i]);
            }
        }
    }
    val[n-1] = queryLazy(0,0,n-1,n-1,n-1);
    cout<<val[n-1]<<endl;
}

Measured memory_bytes: 16452