#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int>v;
const int N=2e5+9;
ll mod=998244353;
ll dp[N];
int x,k;
f (int i)
{
    if (i==x)
        return 1;
    if (dp[i]!=-1)
        return dp[i];
    ll ans=0;
    for (int j=0; j<v.size(); j++)
    {
        if (i+v[j]<=x)
        {
            ans+=f(i+v[j]);
            ans%=mod;
        }
        else
            break;
    }
    return dp[i]=ans;
}
int main()
{
    FASTINOUT;
    cin>>x>>k;
    int l,r;
    for (int i=0; i<k; i++)
    {
        cin>>l>>r;
        for (int j=l; j<=r; j++)
        {
            v.push_back(j);
        }
    }
    sort(v.begin(),v.end());
    memset(dp,-1,sizeof dp);
    cout<<f(1);
    return 0;
}
