//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 998244353  ;
/*#define endl '\n'*/
#define pb push_back
#define mp make_pair

//Check for signed int overflow
// use __builtin_popcount(num) to calculate no.of setbits in num
//s.lower_bound() works in O(logn) whereas lower_bound(s.begin(),s.end(),x) works in O(n)

//Euclid's Algo
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
//Extended Euclid's Algo
ll gcd_ex(ll a,ll b,ll&x,ll&y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll g=gcd_ex(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}
//Multiplicative Modulo Inv
ll multi_mod_inv(ll a,ll m){
    ll x,y;
    ll g=gcd_ex(a,m,x,y);
    if(g!=1){
        return -1;
    }
    x=(x%m+m)%m;
    return x;
}
//Mod division
ll mod_div(ll a,ll b,ll m){
    //(a/b)mod m?
    if(multi_mod_inv(b,m)!=-1){
        return (a%m*multi_mod_inv(b,m)%m)%m;
    }
    else{
        return -1;
    }
}
//lcm
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
//Binary Exponentiation
ll power(ll a,ll n){
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p)%MOD;
    if (n % 2)
        return (p * a)%MOD;
    else
        return p%MOD;
}
//Euler Totient Function
ll phi[1000001]={0};
void euler_totient(ll n){
    for(ll i=0;i<=n;i++){
        phi[i]=i;
    }
    phi[1]=1;
    for(ll i=2;i<=n;i++){
        if(i==phi[i]){
            phi[i]=i-1;//For a prime number phi(p)=p-1
            for(ll j=2*i;j<=n;j+=i){
                phi[j]=phi[j]*(i-1)/i;
            }
        }
    }
}
/*void sieve(vector<ll>&is_prime){
    is_prime[0]=is_prime[1]=0;
    for(ll i=2;i*i<=1000000;i++){
        if(is_prime[i]){
            for(ll j=i*i;j<=1000000;j+=i){
                is_prime[j]=0;
            }
        }
    }
}*/

int32_t main()
{
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(nullptr);
    ll t=1;
    /*cin>>t;*/
    while(t--){
        ll n,k;
        cin>>n>>k;
        vector<pair<ll,ll>>query(k);
        for(ll i=1;i<=k;i++){
            ll L,R;
            cin>>L>>R;
            query[i-1]={L,R};
        }
        ll dp[n+1];
        memset(dp,0,sizeof(dp));
        //dp[i] represents no. of ways to reach ith pos;
        dp[1]=1;
        vector<ll>prefix_sum(n+1,0);
        prefix_sum[1]=1;
        for(ll i=2;i<=n;i++){
            for(ll j=0;j<k;j++){
                ll right=i-query[j].first;
                ll left=i-query[j].second;
                if(right>=1){
                    dp[i]=(dp[i]+prefix_sum[right])%MOD;
                }
                if(left>=1){
                    dp[i]=(dp[i]-prefix_sum[left-1]+MOD)%MOD;
                }
            }
            prefix_sum[i]=(prefix_sum[i-1]+dp[i])%MOD;
            /*for(auto x:prefix_sum){
                cout<<x<<" ";
            }
            cout<<endl;*/
        }
        /*for(ll i=1;i<=n;i++){
            cout<<dp[i]<<" ";
        }*/
        cout<<dp[n];
    }
    return 0;
}

Measured memory_bytes: 6360