#include<bits/stdc++.h>
#define ll long long
#define mod7 1000000007
using namespace std;


void myfunc() {
    long n,k;
    cin >> n >> k;
    long tmp1,tmp2;
    vector<long> d;
    for(int i=0;i<k;i++)
    {
		cin >> tmp1 >> tmp2;
		while(tmp1<=tmp2) {
		d.push_back(tmp1);
		tmp1++;
	}
	}
	//sort(d.begin(),d.end());
	vector<ll> dp(n+1,0);
	dp[1]=1;
	
	int l=d.size(); 
	const ll md=998244353;
	
	for(long i=2;i<=n;i++) {
		for(int j=0;j<l && i-d[j]>0;j++)
		dp[i]=(dp[i]+dp[i-d[j]])%md;
	}
	
	cout << dp[n] << endl;
	
}

int main() {
    long t;
    t=1;
    //cin >> t;
    while(t--)
    myfunc();
    return 0;
}
