#include <iostream>
using namespace std;

int n, k, m = 0;
int l[10], r[10], a[200001];
const int M = 998244353;

int main()
{
	cin >> n >> k;

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

	a[1] = 1;
	a[2] = -1;

	for (int i = 1; i <= n; i++) {
		m = (m + a[i]) % M;

		for (int j = 0; j < k; j++) {
			if (i + l[j] <= n)
				a[i + l[j]] = (a[i + l[j]] + m) % M;

			if(i + r[j] + 1 <= n)
				a[i + r[j] + 1] = (M + a[i + r[j] + 1] - m) % M;
		}
	}		

	cout << m << endl;
}
