//My life was going great until I stumble upon this question ); ):

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

long long MOD = 1000000007; //1e9+7
long long INF = 1e18;
typedef long long ll;
typedef long double ld;
#define pii		pair<int, int>
#define pll		pair<long long, long long>
#define fi 		first
#define se 		second
#define fr(i,a,b) 	for(int i=a;i<b;i++)
#define out2(a,b) 	cout<<a<<" "<<b<<"\n";
#define all(v) 		v.begin(), v.end()
#define pb          	emplace_back

void solve()
{
    ll n, k;
    ll m = 998244353;
    cin>>n>>k;
    ll arr[k][2];
    vector<ll> dp(n+1, 0), pre(n+2, 0);
    for(int i=0;i<k;i++){
        cin>>arr[i][0]>>arr[i][1];
    }
    dp[1]=pre[1]=1;
    ll l, r;
    for(int i=2;i<=n;i++){
        for(int j=0;j<k;j++){
            if(i<arr[j][0]) continue;
            l = arr[j][0];
            r = min(arr[j][1], i-1);
            dp[i] = (dp[i] + pre[i-l]-pre[i-r-1] + m)%m;
        }
        pre[i] = (pre[i-1]+dp[i])%m;
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n]%m;
}

int main() {
	FIO;
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	int test;
	//cin>>test;
	test=1;
	for(int t=1;t<=test;t++){
        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<ans<<"\n";
	}
	return 0;
}
