#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
        return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
        return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}
 
template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
    for (const T &x : s)
        out << x << ' ';
    return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl "\n"
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}



//SUM segment tree
#define MAX 1200000
 
struct node
{
	ll a;
	node()
	{
    	a=0;
	}
};
 
node tree[MAX];
ll lazy[MAX];
 
node combine(node a, node b)
{
	node ans;
	ans.a = (a.a+b.a)%modulo;
	return ans;
}
void push(ll si,ll ss, ll se)
{
	if(lazy[si])
	{
    	tree[si].a+=lazy[si];
        tree[si].a%=modulo;
    	if(ss != se)
    	{
        	lazy[2*si+1]+=lazy[si];
        	lazy[2*si+2]+=lazy[si];

            lazy[2*si+1]%=modulo;
            lazy[2*si+2]%=modulo;
    	}
    	lazy[si] = 0;
	}
}
void build(node arr[], ll ss, ll se, ll si)
{  
	lazy[si] = 0;
	if (ss>se)
    	return;
	if (ss==se)
	{
    	tree[si]=arr[ss];
    	return;
	}
	ll mid=(ss+se)/2;
	build(arr,ss,mid,2*si+1);
	build(arr,mid+1,se,2*si+2);
	tree[si] = combine(tree[2*si+1],tree[2*si+2]);  
}
void update(ll ss, ll se, ll us, ll ue, ll diff, ll si)
{  
	push(si,ss,se);  
	if(ss>se||ss>ue||se<us)
    	return;
	if(ss>=us && se<=ue)
	{
    	lazy[si]=diff;
    	push(si,ss,se);
    	return;
	}
	ll mid=(ss+se)/2;
	update(ss,mid,us,ue,diff,2*si+1);
	update(mid+1,se,us,ue,diff,2*si+2);    
	tree[si] = combine(tree[2*si+1],tree[2*si+2]);
}   
node query(ll ss, ll se, ll qs, ll qe, ll si)
{
	push(si,ss,se);
	if (ss>se||ss>qe||se<qs)
	{
    	node small;
    	small.a = 0;
    	return small; //element for outside query;
	}
	if (ss>=qs && se<=qe)
    	return tree[si];
    ll mid=(ss+se)/2;
	node n1 = query(ss,mid,qs,qe,2*si+1);
	node n2 = query(mid+1,se,qs,qe,2*si+2);
	return combine(n1,n2);
}



int main()
{
    fast();
    ll n,k;
    cin>>n>>k;
    vv a(k,vi(2));
    cin>>a;

    update(0,n-1,0,0,1,0);
    // update(ll ss, ll se, ll us, ll ue, ll diff, ll si)
    // query(ll ss, ll se, ll qs, ll qe, ll si)
    for(ll i=1;i<n;i++)
    {
        for(ll j=0;j<k;j++)
        {
            ll l1=i-a[j][1];
            ll r1=i-a[j][0];

            if(r1>=0)
            {
                l1=max(l1,0ll);
                ll sum=query(0,n-1,l1,r1,0).a;//sum from l...r
                update(0,n-1,i,i,sum,0);
            }
        }
    }
    cout<<query(0,n-1,n-1,n-1,0).a<<nl;
}


Measured memory_bytes: 16064