/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         998244353
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;
signed main()
{
    //fastio;
    int n,m;
    cin>>n>>m;
    set<int> s;
    for(int i=0;i<m;i++)
    {
        int l,r;
        cin>>l>>r;
        for(int j=l;j<=r;j++)s.insert(j);
    }
    int dp[n+1]={0};
    dp[1]=1;
    for(int i=2;i<=n;i++)
    {
        for(auto j:s)
        {
            if(i>j)dp[i]=(dp[i]%MOD+dp[i-j]%MOD)%MOD;
            else break;
            //cout<<i<<" "<<j<<" "<<dp[i]<<endl;
        }
    }
    cout<<dp[n]<<endl;
}

