#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD =  998244353;
const int N = 1e6+5;

typedef int dat;
 
struct SegmentTree
{
    int N;
    vector<dat> st;
    vector<int> lazy;
    vector<bool> isLazy;
    
    dat merge(dat a, dat b)
    {
        return (a+b)%MOD;
    }
 
    void build(int node, int l, int r)
    {
        if(l == r)
        {
            st[node]=0;
            return;
        }
        int m = (l+r)/2;
        build(2*node, l, m);
        build(2*node+1, m+1, r);
        st[node] = merge(st[2*node], st[2*node+1]);
    }
 
    dat query(int node, int l, int r, int i, int j)
    {
        propagate(node, l, r);
        if(l >= i && r <= j)
            return st[node];
        int m = (l+r)/2;
        if(j <= m)
            return query(2*node, l, m, i, j);
        else if(i >= m+1)
            return query(2*node+1, m+1, r, i, j);
        else
            return merge(query(2*node, l, m, i, j), query(2*node+1, m+1, r, i, j));
    }

    void propagate(int node, int l, int r) {
        if(isLazy[node]) {
            //update st[node]
        	st[node]=(st[node]+lazy[node])%MOD;
            if(l!=r) {
                isLazy[2*node]=1; lazy[2*node]=(lazy[2*node]+lazy[node])%MOD;
                isLazy[2*node+1]=1; lazy[2*node+1]=(lazy[2*node+1]+lazy[node])%MOD;
            }
            isLazy[node]=0;
            lazy[node]=0;
        }
    }
 
    //modify arguments and handle point update as per question
    void update(int node, int l, int r, int i, int j, int val)
    {
        propagate(node, l, r);
        if(l >= i && r<=j)
        {
            //Single element value
            lazy[node]=(lazy[node]+val)%MOD;
            isLazy[node] = 1;
            propagate(node,l, r);
            return;
        }
        int m = (l+r)/2;
        if(j <= m) {
            update(2*node, l, m, i, j, val);
            propagate(2*node+1, m+1, r);
        }
        else if(i >= m+1) {
            propagate(2*node, l, m);
            update(2*node+1, m+1, r, i, j, val);
        }
        else {
            update(2*node, l, m, i, j, val);
            update(2*node+1, m+1, r, i, j, val);
        }
        st[node] = merge(st[2*node], st[2*node+1]);
    }
 
    SegmentTree(int tree_size)
    {
        N=tree_size;
        st.resize(4*N+5);
        lazy.resize(4*N+5);
        isLazy.resize(4*N+5);
        build();
    }
 
    void build()
    {
        build(1, 0, N-1);
    }
 
    dat query(int i, int j)
    {
        dat res = query(1, 0, N-1, i, j);
        return res;
    }
    
    void update(int l, int r, int val)
    {
    	if(l>r)
    		return;
        update(1, 0, N-1, l, r, val);
    }
};

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> segs;
	int l,r;
	for(int i=0;i<k;i++) {
		cin>>l>>r;
		segs.pb({l,r});
	}
	sort(segs.begin(), segs.end());
	int pr = -1;
	int pi = -1;
	vector<pair<int,int>> nms;
	for(int i=0;i<k;i++) {
		if(segs[i].first>pr) {
			pr = segs[i].second;
			nms.pb({segs[i]});
			pi=i;
		}
		else {
			pr = segs[i].second;
			nms[pi].second = pr;
		}
	}

	SegmentTree st = SegmentTree(n);
	st.update(0,0,1);
	k = nms.size();
	for(int i=0;i<n;i++) {
		int cans = st.query(i,i);
		for(int j=0;j<k;j++) {
			st.update(i+nms[j].first, min(i+nms[j].second, (int)n-1), cans);
		}
	}

	cout<<st.query(n-1,n-1);


	return 0;
}

Measured memory_bytes: 16020