/**
 *  author: nayakashutosh9
 *	[2020-09-19 17:25]
**/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define inf 1e18
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> pbds;
const int N = 200005;
/*******************************************************/
int n, k;
int dp[N];
set<int> a;
int check(int i) {
	if (i == n) return 1;
	if (i > n) return 0;
	if (dp[i] != -1) return dp[i];
	int q = 0;
	for (int j : a) {
		q = (q + check(i + j)) % modd;
	}
	return dp[i] = q % modd;
}
void solve() {
	cin >> n >> k;
	a.clear();
	for (int i = 0; i < k; i++) {
		int l, r; cin >> l >> r;
		for (int j = l; j <= r; j++) a.insert(j);
	}
	for (int i = 0; i < n; i++) dp[i] = -1;
	int ans = check(1) % modd;
	cout << ans % modd << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T = 1;
	// cin >> T; cin.ignore();
	for (int i = 1; i <= T; i++) {
		// cout << "Case #" << i << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}