#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll int
#define M 1000000007 
#define MM 998244353
#define INF 4e18
using namespace std;
 
typedef tree<ll, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    ordered_set; 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    /*ll t,tcitr;
    cin>>t;
    tcitr=0;
    while(tcitr<t)
    {*/
        ll n,i,j,k,p;
        cin>>n>>k;
        ll pre[n+2]={};
        for(i=0;i<k;i++)
        {
            cin>>j>>p;
            pre[j]++;
            pre[p+1]--;
        }
        ll cnt=0;
        vector<ll> v;
        ll dp[n+1]={};
        dp[1]=1;
        for(i=0;i<=n;i++)
        {
            cnt+=pre[i];
            if(cnt>0)v.push_back(i);
            for(j=0;j<v.size();j++)
            {
                dp[i]+=dp[i-v[j]];
                if(dp[i]>=MM)dp[i]-=MM;
            }
        }
        cout<<dp[n]<<"\n";
        /*tcitr++;
    }*/
    return 0;
}