/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o D.exe D.cpp 
Execute: ./D
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 
	// Input 
	int n, k;
	cin >> n >> k;
	int left[k], right[k]; 
	for(int i = 0; i < k; i++) {
		cin >> left[i] >> right[i]; 
	} 
	int mod = 998244353; 
	
	// Solve -- naive? O(N^2) worst case. 
	int r[n+1] = {0}; 
	r[1] = 1; 
	for(int i = 1; i < n; i++) { 
		for(int w = 0; w < k; w++) {
			for(int j = left[w]; j <= right[w] && i+j<=n; j++) {
				// cout << i << "\t" << j << "\t" << r[i+j] << endl; 
				r[i+j] += r[i]; 
				r[i+j] %= mod; 
			}
		}
	}
	
	cout << r[n] << endl; 
	
	return 0; 
} 
