#include <iostream>
#include <vector>
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);

	int n, k;
	cin >> n >> k;

	int* l = new int[k] {0};
	int* r = new int[k] {0};
	
	for (int i = 0; i < k; i++)
		cin >> l[i] >> r[i];

	long long* s = new int[k] {0};
	long long dp[200000] = { 0 };
	long long temp;

	dp[1] = 1;

	const int m = 998244353;

	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			if (i - l[j] >= 1)
				s[j] = (s[j] + dp[i - l[j]]) % m;			
			if (i - r[j] - 1 >= 1) {
				temp = s[j] - dp[i - r[j] - 1];
				if (temp < 0)
					temp += m;
				s[j] = temp;
			}
			dp[i] = (dp[i] + s[j]) % 998244353;
		}		
	}

	cout << dp[n];



	return 0;
}