//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    // #pragma GCC optimize("Ofast")
    using namespace std;
    //library
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double
    //scankar
    #define sz(x) (int)(x).size()
    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    typedef map<int,int> mii;
    typedef map<int,bool> mib;
    typedef map<char,int> mci;
    typedef map<string,int> msi;
    
    const int INF = 1e18L + 5;
    const int MAX = 2e6 + 7;
    const int MOD =  998244353;
    const long double PI  =3.141592653589793238463;
    //direction
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;
    //debugger

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int seg[MAX], a[MAX];
     
    void build(int node, int st, int end)
    {
        if(st==end)
        {
            seg[node]=a[st];
        } 
        else
        {
            int mid = (st+end)/2;
            build(2*node,st,mid);
            build(2*node+1,mid+1,end);
            seg[node]=(seg[2*node]+seg[2*node+1])%MOD;
        }
    }
     
    void update(int node, int st, int end, int idx, int val)
    {
        if(st==end)
        {
            a[st]=(a[st]+val)%MOD;
            seg[node]=(seg[node]+val)%MOD;
        } 
        else
        {
            int mid = (st+end)/2;
            if(idx>=st&&idx<=mid) update(2*node,st,mid,idx,val);
            else if(idx>=mid+1&&idx<=end) update(2*node+1,mid+1,end,idx,val);
     
            seg[node]=(seg[2*node]+seg[2*node+1])%MOD;
        }
    }
     
    int query(int node, int st, int end, int l, int r)
    {
        if(l>end || st>r)
            return 0;
        if(st>=l && end<=r) return seg[node];
     
        int mid = (st+end)/2;
        return (query(2*node,st,mid,l,r) + query(2*node+1,mid+1,end,l,r))%MOD; 
    }

    int ll[15],rr[15];

    void solve()
    {
        cin>>n>>k;
        fo(i,0,k)
        {
            cin>>ll[i]>>rr[i];
        }
        
        a[1]=1;
        build(1,1,n);

        fo(i,2,n+1)
        {
            fo(j,0,k)
            {
                l=i-ll[j];
                if(l>=1)
                {
                    r=max(1ll,i-rr[j]);
                    update(1,1,n,i,query(1,1,n,r,l));
                }
            }
        }
        cout<<a[n]<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 9232