#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
ll M=998244353;


int main() {
	int n,k;
	cin>>n>>k;
	vector <int> v;
	int method[n+1]={0};

	for (int i = 0; i < k; i++) {
	    int x,y;cin>>x>>y;
	    for (int j= x; j <= y; j++) {
	        v.pb(j);
	    }
	}
	method[1]=1;
	for(int i=2;i<=n;i++){
	    for(auto u:v)
	     if((i-u)>=1){
	       method[i]+=method[i-u];
	       method[i]%=M;


	     }
	}
	cout<<method[n];
	
	return 0;
}