#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

#define mod 998244353
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	FASTIO

	ll n, k;
	cin >> n >> k;

	ll l[k], r[k];
	for(ll i = 0; i < k; i ++)
	{
		cin >> l[i] >> r[i];
	}	

	ll dp[n + 1] = {0};
	ll pref[n + 1] = {0};
	pref[1] = 1;
	dp[1] = 1;
	for(ll i = 2; i <= n; i ++)
	{
		for(ll j = 0; j < k; j ++)
		{
			if(i >= r[j])
			{
				dp[i] += ((pref[i - l[j]] % mod - pref[i - r[j] - 1] % mod) % mod + mod) % mod % mod;
			}
			else if(i >= l[j])
				dp[i] += ((pref[i - l[j]] % mod - pref[0] % mod) % mod + mod) % mod % mod;
		}
		// debug2(i, dp[i])
		pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
	}
	cout << dp[n] << endl;
}