#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n,k,f[200005]={0,1},d[200005]={0,1,-1};
struct node{int l,r;}a[15];
bool cmp(node a,node b){return a.l<b.r;}
int main(){
    cin>>n>>k;
    for(int i=1;i<=k;i++)cin>>a[i].l>>a[i].r;
    sort(a+1,a+1+k,cmp);
    for(int i=1;i<=n;i++){
        f[i]=(f[i-1]+d[i])%mod;
//        cout<<f[i]<<" "<<d[i]<<endl;
        if(f[i])for(int j=1;j<=k&&a[j].l+i<=n;j++){
            d[i+a[j].l]=(d[i+a[j].l]+f[i])%mod,d[i+a[j].r+1]=(d[i+a[j].r+1]-f[i])%mod;
//            cout<<i<<" "<<i+a[j].l<<" "<<i+a[j].r+1<<endl;
        }
    }
    cout<<(f[n]+mod)%mod<<endl;
    return 0;
}
