/* Aditya0412 */
    #include <bits/stdc++.h>
    using namespace std; 
    #define int long long 
    #define pb push_back 
    #define vii vector < int > 
    #define pii pair < int , int >
    #define fi first
    #define all(a)      (a).begin(),(a).end()
    #define si(x)       (int)((x).size())
    #define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
    #define se second 
    #define endl        '\n'
    #define f(i,a,b)    for(int i=a;i<b;i++)
    #define mem(a,x)          memset(a,x,sizeof(a))
    #define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    const int  mod=998244353;
    // const int  mod = 1000000000+7;
    const int  N=200000+6;
    #define M_PI           3.14159265358979323846

    // int x2[]={+1,-1,+0,+0};
    // int y2[]={+0,+0,+1,-1};
    // int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
    // int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
    // int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
    // int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};

    // === Debug macro starts here ===

    int recur_depth = 0;
    #ifdef DEBUG
    #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
    #else
    #define dbg(x)
    #endif
    template<typename Ostream, typename Cont>
    typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
        os<<"[";
        for(auto& x:v){os<<x<<", ";}
        return os<<"]";
    }
    template<typename Ostream, typename ...Ts>
    Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
        return os<<"{"<<p.first<<", "<<p.second<<"}";
    }

    // === Debug macro ends here ===
int stree[4*N];int dp[N];
void build(int node,int st,int en)
{
    if(st==en)
    {
        stree[node]=dp[st];
        stree[node]%=mod;
    }
    else
    {
        int mid=(st+en)/2;
        build(node*2,st,mid);
        build(node*2+1,mid+1,en);
        stree[node]=stree[node*2]+stree[node*2+1];
        stree[node]%=mod;
    }
}
void update(int node,int st,int en,int x,int y)
{
    if(st==en)
    {
        stree[node]=dp[st];
        stree[node]%=mod;
    }
    else
    {
        int mid=(st+en)/2;
        if(x>=st and x<=mid)
        update(node*2,st,mid,x,y);
        else
        update(node*2+1,mid+1,en,x,y);
        stree[node]=stree[node*2]+stree[node*2+1];stree[node]%=mod;
    }
}
int query(int node,int st,int en,int l,int r)
{
    if(st>=l and en<=r)
    return stree[node];
    else if(en<l or st>r)
    return 0;
    else
    {
        int mid=(st+en)/2;
        int x=query(node*2,st,mid,l,r);
        int y=query(node*2+1,mid+1,en,l,r);
        int ans=(x+y)%mod;
        return ans;
    }
    
}
    main() 
    {
        fastIO;
        int n;cin>>n;
        int k;cin>>k;
        vector< pair<int,int> > v(k);
        f(i,0,k)
        {
            int x,y;cin>>x>>y;
            v[i]={x,y};

        }
        mem(dp,0);
        dp[n]=1;
        build(1,1,n);
        for(int i=n-1;i>=1;i--)
        {
            for(int j=0;j<k;j++)
            {
                int l=i+v[j].fi;
                int r=i+v[j].se;
                if(l>n)
                continue;
                else
                {
                    r=min(r,n);
                    int x=query(1,1,n,l,r);
                    dp[i]+=x;
                    dp[i]%=mod;
                }
            }
            update(1,1,n,i,dp[i]);
        }
        cout<<dp[1];

        
        
    } 

Measured memory_bytes: 9288